HTML_QuickForm2
[ class tree: HTML_QuickForm2 ] [ index: HTML_QuickForm2 ] [ all elements ]

Source for file wizard.php

Documentation is available at wizard.php

  1. <?php
  2. /**
  3.  * Usage example for HTML_QuickForm2_Controller: wizard
  4.  *
  5.  * @author  Alexey Borzov <avb@php.net>
  6.  * @ignore
  7.  */
  8.  
  9. require_once 'HTML/QuickForm2.php';
  10. require_once 'HTML/QuickForm2/Controller.php';
  11. require_once 'HTML/QuickForm2/Renderer.php';
  12.  
  13. // Load some default action handlers
  14. require_once 'HTML/QuickForm2/Controller/Action/Next.php';
  15. require_once 'HTML/QuickForm2/Controller/Action/Back.php';
  16. require_once 'HTML/QuickForm2/Controller/Action/Jump.php';
  17. require_once 'HTML/QuickForm2/Controller/Action/Display.php';
  18.  
  19. // Start the session, form-page values will be kept there
  20.  
  21. {
  22.     protected function populateForm()
  23.     {
  24.         $fs $this->form->addElement('fieldset')->setLabel('Wizard page 1 of 3');
  25.  
  26.         $radioGroup $fs->addElement('group')->setLabel('Are you absolutely sure?');
  27.         $radioGroup->addElement('radio''iradYesNo'array('value' => 'Y')array('content' => 'Yes'));
  28.         $radioGroup->addElement('radio''iradYesNo'array('value' => 'N')array('content' => 'No'));
  29.  
  30.         $fs->addElement('submit'$this->getButtonName('next')array('value' => 'Next >>'));
  31.  
  32.         $radioGroup->addRule('required''Check Yes or No');
  33.  
  34.         $this->setDefaultAction('next');
  35.     }
  36. }
  37.  
  38. {
  39.     protected function populateForm()
  40.     {
  41.         $fs $this->form->addElement('fieldset')->setLabel('Wizard page 2 of 3');
  42.  
  43.         $nameGroup $fs->addElement('group''name'array('id' => 'nameGrp'))
  44.                         ->setLabel('Name:')
  45.                         ->setSeparator('<span class="separator">,</span>');
  46.         $nameGroup->addElement('text''last'array('size' => 20))
  47.                   ->setLabel('Last')
  48.                   ->addRule('required''Last name is required');
  49.         $nameGroup->addElement('text''first'array('size' => 20))
  50.                   ->setLabel('First');
  51.  
  52.         $buttonGroup $fs->addElement('group');
  53.         $buttonGroup->addElement('submit'$this->getButtonName('back')array('value' => '<< Back'));
  54.         $buttonGroup->addElement('submit'$this->getButtonName('next')array('value' => 'Next >>'));
  55.  
  56.         $this->setDefaultAction('next');
  57.     }
  58. }
  59.  
  60. {
  61.     protected function populateForm()
  62.     {
  63.         $fs $this->form->addElement('fieldset')->setLabel('Wizard page 3 of 3');
  64.  
  65.         $fs->addElement('textarea''itxaTest'array('rows' => 5'cols' => 40))
  66.            ->setLabel('Parting words:')
  67.            ->addRule('required''Say something!');
  68.  
  69.         $buttonGroup $fs->addElement('group');
  70.         $buttonGroup->addElement('submit'$this->getButtonName('back')array('value' => '<< Back'));
  71.         $buttonGroup->addElement('submit'$this->getButtonName('next')array('value' => 'Finish'));
  72.  
  73.         $this->setDefaultAction('next');
  74.     }
  75. }
  76.  
  77. {
  78.     protected function renderForm(HTML_QuickForm2 $form)
  79.     {
  80. ?>
  81. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  82.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  83. <html xmlns="http://www.w3.org/1999/xhtml">
  84.   <head>
  85.     <style type="text/css">
  86. /* Set up custom font and form width */
  87. body {
  88.     margin-left: 10px;
  89.     font-family: Arial,sans-serif;
  90.     font-size: small;
  91. }
  92.  
  93. .quickform {
  94.     min-width: 500px;
  95.     max-width: 600px;
  96.     width: 560px;
  97. }
  98.  
  99. .separator {
  100.     float: left;
  101.     margin: 0.7em 0 0 0.1em;
  102. }
  103.  
  104. /* Use default styles included with the package */
  105.  
  106. <?php
  107.     if ('@data_dir@' != '@' 'data_dir@'{
  108.         $filename '@data_dir@/HTML_QuickForm2/quickform.css';
  109.     else {
  110.         $filename dirname(dirname(dirname(__FILE__))) '/data/quickform.css';
  111.     }
  112.     readfile($filename);
  113. ?>
  114.     </style>
  115.     <title>HTML_QuickForm2 basic elements example</title>
  116.   </head>
  117.   <body>
  118. <?php
  119.     $renderer HTML_QuickForm2_Renderer::factory('default');
  120.     $renderer->setElementTemplateForGroupId(
  121.         'nameGrp''html_quickform2_element',
  122.         '<div class="element<qf:error> error</qf:error>"><qf:error><span class="error">{error}</span><br /></qf:error>{element}<br /><label for="{id}"><qf:required><span class="required">* </span></qf:required>{label}</label></div>'
  123.     );
  124.     $renderer->setTemplateForId(
  125.         'nameGrp''<div class="row"><p class="label"><qf:required><span class="required">*</span></qf:required><qf:label><label>{label}</label></qf:label></p>{content}</div>'
  126.     );
  127.     echo $form->render($renderer);
  128. ?>
  129.   </body>
  130. </html>
  131. <?php
  132.     }
  133. }
  134.  
  135. {
  136.     public function perform(HTML_QuickForm2_Controller_Page $page$name)
  137.     {
  138.         echo "Submit successful!<br>\n<pre>\n";
  139.         var_dump($page->getController()->getValue());
  140.         echo "\n</pre>\n";
  141.     }
  142. }
  143.  
  144. $wizard = new HTML_QuickForm2_Controller('Wizard');
  145. $wizard->addPage(new PageFirst(new HTML_QuickForm2('page1')));
  146. $wizard->addPage(new PageSecond(new HTML_QuickForm2('page2')));
  147. $wizard->addPage(new PageThird(new HTML_QuickForm2('page3')));
  148.  
  149. // We actually add these handlers here for the sake of example
  150. // They can be automatically loaded and added by the controller
  151. $wizard->addHandler('next'new HTML_QuickForm2_Controller_Action_Next());
  152. $wizard->addHandler('back'new HTML_QuickForm2_Controller_Action_Back());
  153. $wizard->addHandler('jump'new HTML_QuickForm2_Controller_Action_Jump());
  154.  
  155. // This is the action we should always define ourselves
  156. $wizard->addHandler('process'new WizardProcess());
  157. // We redefine 'display' handler to use the proper stylesheets
  158. $wizard->addHandler('display'new WizardDisplay());
  159.  
  160. $wizard->run();
  161. ?>

Documentation generated on Wed, 10 Apr 2019 08:56:11 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.