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

Source for file statemachine.php

Documentation is available at statemachine.php

  1. <?php
  2. /**
  3.  * Example for HTML_QuickForm_Controller: Statemachine
  4.  * Going to either of the two pages based on user input
  5.  *
  6.  * @version SVN: $Id: statemachine.php 289084 2009-10-02 06:53:09Z avb $
  7.  * @author  Donald Lobo <lobo@groundspring.org>
  8.  * @ignore
  9.  */
  10.  
  11. require_once 'HTML/QuickForm/Controller.php';
  12.  
  13. // Load some default action handlers
  14. require_once 'HTML/QuickForm/Action/Next.php';
  15. require_once 'HTML/QuickForm/Action/Back.php';
  16. require_once 'HTML/QuickForm/Action/Jump.php';
  17. require_once 'HTML/QuickForm/Action/Display.php';
  18.  
  19. // Start the session, form-page values will be kept there
  20.  
  21. {
  22.     function perform(&$page$actionName)
  23.     {
  24.       // save the form values and validation status to the session
  25.         $page->isFormBuilt(or $page->buildForm();
  26.         $pageName =  $page->getAttribute('id');
  27.         $data     =$page->controller->container();
  28.         $data['values'][$pageName$page->exportValues();
  29.         if (PEAR::isError($valid $page->validate())) {
  30.             return $valid;
  31.         }
  32.         $data['valid'][$pageName$valid;
  33.  
  34.         // Modal form and page is invalid: don't go further
  35.         if ($page->controller->isModal(&& !$data['valid'][$pageName]{
  36.             return $page->handle('display');
  37.         }
  38.  
  39.         $nextName $data['values'][$pageName]['iradPageAB'];
  40.         if (empty($nextName)) {
  41.             $nextName 'page1';
  42.         }
  43.         if ($nextName == 'page2a'{
  44.             $data['valid']['page2b'= true;
  45.         else {
  46.             $data['valid']['page2a'= true;
  47.         }
  48.         $next =$page->controller->getPage($nextName);
  49.         $next->handle('jump');
  50.     }
  51. }
  52.  
  53.  
  54. {
  55.     function perform(&$page$actionName)
  56.     {
  57.       // save the form values and validation status to the session
  58.         $page->isFormBuilt(or $page->buildForm();
  59.         $pageName =  $page->getAttribute('id');
  60.         $data     =$page->controller->container();
  61.         $data['values'][$pageName$page->exportValues();
  62.         if (PEAR::isError($valid $page->validate())) {
  63.             return $valid;
  64.         }
  65.         $data['valid'][$pageName$valid;
  66.  
  67.         // Modal form and page is invalid: don't go further
  68.         if ($page->controller->isModal(&& !$data['valid'][$pageName]{
  69.             return $page->handle('display');
  70.         }
  71.  
  72.         // More pages?
  73.         $next =$page->controller->getPage('page3');
  74.         $next->handle('jump');
  75.     }
  76. }
  77.  
  78.  
  79. {
  80.     function perform(&$page$actionName)
  81.     {
  82.         // save the form values and validation status to the session
  83.         $page->isFormBuilt(or $page->buildForm();
  84.         $pageName =  $page->getAttribute('id');
  85.         $data     =$page->controller->container();
  86.         $data['values'][$pageName$page->exportValues();
  87.         if (!$page->controller->isModal()) {
  88.             if (PEAR::isError($valid $page->validate())) {
  89.                 return $valid;
  90.             }
  91.             $data['valid'][$pageName$valid;
  92.         }
  93.  
  94.         $prev =$page->controller->getPage('page1');
  95.         $prev->handle('jump');
  96.     }
  97. }
  98.  
  99.  
  100. {
  101.     function perform(&$page$actionName)
  102.     {
  103.         // save the form values and validation status to the session
  104.         $page->isFormBuilt(or $page->buildForm();
  105.         $pageName =  $page->getAttribute('id');
  106.         $data     =$page->controller->container();
  107.         $data['values'][$pageName$page->exportValues();
  108.         if (!$page->controller->isModal()) {
  109.             if (PEAR::isError($valid $page->validate())) {
  110.                 return $valid;
  111.             }
  112.             $data['valid'][$pageName$valid;
  113.         }
  114.  
  115.         $prev =$page->controller->getPage($data['values']['page1']['iradPageAB']);
  116.         $prev->handle('jump');
  117.     }
  118. }
  119.  
  120.  
  121. {
  122.     function buildForm()
  123.     {
  124.         $this->_formBuilt = true;
  125.  
  126.         $this->addElement('header',     null'StateMachine page 1 of 3');
  127.  
  128.         $radio[&$this->createElement('radio'nullnull'Page 2A''page2a');
  129.         $radio[&$this->createElement('radio'nullnull'Page 2B''page2b');
  130.         $this->addGroup($radio'iradPageAB''Proceed to page:');
  131.  
  132.         $this->addElement('submit',     $this->getButtonName('next')'Next >>');
  133.  
  134.         $this->addRule('iradPageAB''Select the page''required');
  135.  
  136.         $this->setDefaultAction('next');
  137.     }
  138. }
  139.  
  140. {
  141.     function buildForm()
  142.     {
  143.         $this->_formBuilt = true;
  144.  
  145.         $this->addElement('header',     null'StateMachine page 2A of 3');
  146.  
  147.         $name['last']  &$this->createElement('text''last'nullarray('size' => 30));
  148.         $name['first'&$this->createElement('text''first'nullarray('size' => 20));
  149.         $this->addGroup($name'name''Name (last, first):'',&nbsp;');
  150.  
  151.         $prevnext[=$this->createElement('submit',   $this->getButtonName('back')'<< Back');
  152.         $prevnext[=$this->createElement('submit',   $this->getButtonName('next')'Next >>');
  153.         $this->addGroup($prevnextnull'''&nbsp;'false);
  154.  
  155.         $this->addGroupRule('name'array('last' => array(array('Last name is required''required'))));
  156.  
  157.         $this->setDefaultAction('next');
  158.     }
  159. }
  160.  
  161. {
  162.     function buildForm()
  163.     {
  164.         $this->_formBuilt = true;
  165.  
  166.         $this->addElement('header',     null'StateMachine page 2B of 3');
  167.  
  168.         $this->addElement('textarea',   'itxaTest''Description:'array('rows' => 5'cols' => 40));
  169.  
  170.         $prevnext[=$this->createElement('submit',   $this->getButtonName('back')'<< Back');
  171.         $prevnext[=$this->createElement('submit',   $this->getButtonName('next')'Next >>');
  172.         $this->addGroup($prevnextnull'''&nbsp;'false);
  173.  
  174.         $this->addRule('itxaTest''Say something!''required');
  175.  
  176.         $this->setDefaultAction('next');
  177.     }
  178. }
  179.  
  180. {
  181.     function buildForm()
  182.     {
  183.         $this->_formBuilt = true;
  184.  
  185.         $this->addElement('header',     null'StateMachine page 3 of 3');
  186.  
  187.         $this->addElement('text',   'fourthTextBox''Final Text:'array('size' => 20'maxlen' => 40));
  188.  
  189.         $prevnext[=$this->createElement('submit',   $this->getButtonName('back')'<< Back');
  190.         $prevnext[=$this->createElement('submit',   $this->getButtonName('next')'Finish');
  191.         $this->addGroup($prevnextnull'''&nbsp;'false);
  192.  
  193.         $this->addRule('fourthTextBox''Say something!''required');
  194.  
  195.         $this->setDefaultAction('next');
  196.     }
  197. }
  198.  
  199. {
  200.     function perform(&$page$actionName)
  201.     {
  202.         echo "Submit successful!<br>\n<pre>\n";
  203.         var_dump($page->controller->exportValues());
  204.         echo "\n</pre>\n";
  205.     }
  206. }
  207.  
  208. $statemachine =new HTML_QuickForm_Controller('StateMachine');
  209.  
  210. $page1  =new PageFirst('page1');
  211. $page2a =new PageSecondAlpha('page2a');
  212. $page2b =new PageSecondBeta('page2b');
  213. $page3  =new PageThird('page3');
  214.  
  215. $statemachine->addPage($page1);
  216. $statemachine->addPage($page2a);
  217. $statemachine->addPage($page2b);
  218. $statemachine->addPage($page3);
  219.  
  220. $page1->addAction('next'new PageFirstActionNext());
  221. $page2a->addAction('next'new PageSecondActionNext());
  222. $page2a->addAction('back'new PageSecondActionBack());
  223. $page2b->addAction('next'new PageSecondActionNext());
  224. $page2b->addAction('back'new PageSecondActionBack());
  225. $page3->addAction('back'new PageThirdActionBack());
  226.  
  227. // We actually add these handlers here for the sake of example
  228. // They can be automatically loaded and added by the controller
  229. $statemachine->addAction('display'new HTML_QuickForm_Action_Display());
  230. $statemachine->addAction('next'new HTML_QuickForm_Action_Next());
  231. $statemachine->addAction('back'new HTML_QuickForm_Action_Back());
  232. $statemachine->addAction('jump'new HTML_QuickForm_Action_Jump());
  233.  
  234. // This is the action we should always define ourselves
  235. $statemachine->addAction('process'new ActionProcess());
  236.  
  237. $statemachine->run();
  238. ?>

Documentation generated on Mon, 11 Mar 2019 15:34:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.