home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / wizard.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  3.5 KB  |  110 lines

  1. <?php
  2. /**
  3.  * Example 2 for HTML_QuickForm_Controller: Wizard
  4.  * 
  5.  * $Id: wizard.php,v 1.2 2003/10/02 12:49:38 avb Exp $
  6.  */
  7.  
  8. require_once 'HTML/QuickForm/Controller.php';
  9.  
  10. // Load some default action handlers
  11. require_once 'HTML/QuickForm/Action/Next.php';
  12. require_once 'HTML/QuickForm/Action/Back.php';
  13. require_once 'HTML/QuickForm/Action/Jump.php';
  14. require_once 'HTML/QuickForm/Action/Display.php';
  15.  
  16. // Start the session, form-page values will be kept there
  17. session_start();
  18.  
  19. class PageFirst extends HTML_QuickForm_Page
  20. {
  21.     function buildForm()
  22.     {
  23.         $this->_formBuilt = true;
  24.  
  25.         $this->addElement('header',     null, 'Wizard page 1 of 3');
  26.  
  27.         $radio[] = &$this->createElement('radio', null, null, 'Yes', 'Y');
  28.         $radio[] = &$this->createElement('radio', null, null, 'No', 'N');
  29.         $this->addGroup($radio, 'iradYesNo', 'Are you absolutely sure?');
  30.  
  31.         $this->addElement('submit',     $this->getButtonName('next'), 'Next >>');
  32.  
  33.         $this->addRule('iradYesNo', 'Check Yes or No', 'required');
  34.  
  35.         $this->setDefaultAction('next');
  36.     }
  37. }
  38.  
  39. class PageSecond extends HTML_QuickForm_Page
  40. {
  41.     function buildForm()
  42.     {
  43.         $this->_formBuilt = true;
  44.  
  45.         $this->addElement('header',     null, 'Wizard page 2 of 3');
  46.  
  47.         $name['last']  = &$this->createElement('text', 'last', null, array('size' => 30));
  48.         $name['first'] = &$this->createElement('text', 'first', null, array('size' => 20));
  49.         $this->addGroup($name, 'name', 'Name (last, first):', ', ');
  50.  
  51.         $prevnext[] =& $this->createElement('submit',   $this->getButtonName('back'), '<< Back');
  52.         $prevnext[] =& $this->createElement('submit',   $this->getButtonName('next'), 'Next >>');
  53.         $this->addGroup($prevnext, null, '', ' ', false);
  54.         
  55.         $this->addGroupRule('name', array('last' => array(array('Last name is required', 'required'))));
  56.  
  57.         $this->setDefaultAction('next');
  58.     }
  59. }
  60.  
  61. class PageThird extends HTML_QuickForm_Page
  62. {
  63.     function buildForm()
  64.     {
  65.         $this->_formBuilt = true;
  66.  
  67.         $this->addElement('header',     null, 'Wizard page 3 of 3');
  68.  
  69.         $this->addElement('textarea',   'itxaTest', 'Parting words:', array('rows' => 5, 'cols' => 40));
  70.  
  71.         $prevnext[] =& $this->createElement('submit',   $this->getButtonName('back'), '<< Back');
  72.         $prevnext[] =& $this->createElement('submit',   $this->getButtonName('next'), 'Finish');
  73.         $this->addGroup($prevnext, null, '', ' ', false);
  74.  
  75.         $this->addRule('itxaTest', 'Say something!', 'required');
  76.  
  77.         $this->setDefaultAction('next');
  78.     }
  79. }
  80.  
  81.  
  82.  
  83. class ActionProcess extends HTML_QuickForm_Action
  84. {
  85.     function perform(&$page, $actionName)
  86.     {
  87.         echo "Submit successful!<br>\n<pre>\n";
  88.         var_dump($page->controller->exportValues());
  89.         echo "\n</pre>\n";
  90.     }
  91. }
  92.  
  93. $wizard =& new HTML_QuickForm_Controller('Wizard');
  94. $wizard->addPage(new PageFirst('page1'));
  95. $wizard->addPage(new PageSecond('page2'));
  96. $wizard->addPage(new PageThird('page3'));
  97.  
  98. // We actually add these handlers here for the sake of example
  99. // They can be automatically loaded and added by the controller
  100. $wizard->addAction('display', new HTML_QuickForm_Action_Display());
  101. $wizard->addAction('next', new HTML_QuickForm_Action_Next());
  102. $wizard->addAction('back', new HTML_QuickForm_Action_Back());
  103. $wizard->addAction('jump', new HTML_QuickForm_Action_Jump());
  104.  
  105. // This is the action we should always define ourselves
  106. $wizard->addAction('process', new ActionProcess());
  107.  
  108. $wizard->run();
  109. ?>
  110.