Source for file statemachine.php
Documentation is available at statemachine.php
* Example for HTML_QuickForm_Controller: Statemachine
* Going to either of the two pages based on user input
* @version SVN: $Id: statemachine.php 289084 2009-10-02 06:53:09Z avb $
* @author Donald Lobo <lobo@groundspring.org>
require_once 'HTML/QuickForm/Controller.php';
// Load some default action handlers
require_once 'HTML/QuickForm/Action/Next.php';
require_once 'HTML/QuickForm/Action/Back.php';
require_once 'HTML/QuickForm/Action/Jump.php';
require_once 'HTML/QuickForm/Action/Display.php';
// Start the session, form-page values will be kept there
function perform(&$page, $actionName)
// save the form values and validation status to the session
$page->isFormBuilt () or $page->buildForm ();
$pageName = $page->getAttribute ('id');
$data = & $page->controller ->container ();
$data['values'][$pageName] = $page->exportValues ();
if (PEAR ::isError ($valid = $page->validate ())) {
$data['valid'][$pageName] = $valid;
// Modal form and page is invalid: don't go further
if ($page->controller ->isModal () && !$data['valid'][$pageName]) {
return $page->handle ('display');
$nextName = $data['values'][$pageName]['iradPageAB'];
if ($nextName == 'page2a') {
$data['valid']['page2b'] = true;
$data['valid']['page2a'] = true;
$next = & $page->controller ->getPage ($nextName);
function perform(&$page, $actionName)
// save the form values and validation status to the session
$page->isFormBuilt () or $page->buildForm ();
$pageName = $page->getAttribute ('id');
$data = & $page->controller ->container ();
$data['values'][$pageName] = $page->exportValues ();
if (PEAR ::isError ($valid = $page->validate ())) {
$data['valid'][$pageName] = $valid;
// Modal form and page is invalid: don't go further
if ($page->controller ->isModal () && !$data['valid'][$pageName]) {
return $page->handle ('display');
$next = & $page->controller ->getPage ('page3');
function perform(&$page, $actionName)
// save the form values and validation status to the session
$page->isFormBuilt () or $page->buildForm ();
$pageName = $page->getAttribute ('id');
$data = & $page->controller ->container ();
$data['values'][$pageName] = $page->exportValues ();
if (!$page->controller ->isModal ()) {
if (PEAR ::isError ($valid = $page->validate ())) {
$data['valid'][$pageName] = $valid;
$prev = & $page->controller ->getPage ('page1');
function perform(&$page, $actionName)
// save the form values and validation status to the session
$page->isFormBuilt () or $page->buildForm ();
$pageName = $page->getAttribute ('id');
$data = & $page->controller ->container ();
$data['values'][$pageName] = $page->exportValues ();
if (!$page->controller ->isModal ()) {
if (PEAR ::isError ($valid = $page->validate ())) {
$data['valid'][$pageName] = $valid;
$prev = & $page->controller ->getPage ($data['values']['page1']['iradPageAB']);
$this->_formBuilt = true;
$this->addElement ('header', null , 'StateMachine page 1 of 3');
$radio[] = &$this->createElement ('radio', null , null , 'Page 2A', 'page2a');
$radio[] = &$this->createElement ('radio', null , null , 'Page 2B', 'page2b');
$this->addGroup ($radio, 'iradPageAB', 'Proceed to page:');
$this->addElement ('submit', $this->getButtonName('next'), 'Next >>');
$this->addRule ('iradPageAB', 'Select the page', 'required');
$this->_formBuilt = true;
$this->addElement ('header', null , 'StateMachine page 2A of 3');
$name['last'] = &$this->createElement ('text', 'last', null , array ('size' => 30 ));
$name['first'] = &$this->createElement ('text', 'first', null , array ('size' => 20 ));
$this->addGroup ($name, 'name', 'Name (last, first):', ', ');
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('back'), '<< Back');
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('next'), 'Next >>');
$this->addGroup ($prevnext, null , '', ' ', false );
$this->addGroupRule ('name', array ('last' => array (array ('Last name is required', 'required'))));
$this->_formBuilt = true;
$this->addElement ('header', null , 'StateMachine page 2B of 3');
$this->addElement ('textarea', 'itxaTest', 'Description:', array ('rows' => 5 , 'cols' => 40 ));
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('back'), '<< Back');
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('next'), 'Next >>');
$this->addGroup ($prevnext, null , '', ' ', false );
$this->addRule ('itxaTest', 'Say something!', 'required');
$this->_formBuilt = true;
$this->addElement ('header', null , 'StateMachine page 3 of 3');
$this->addElement ('text', 'fourthTextBox', 'Final Text:', array ('size' => 20 , 'maxlen' => 40 ));
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('back'), '<< Back');
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('next'), 'Finish');
$this->addGroup ($prevnext, null , '', ' ', false );
$this->addRule ('fourthTextBox', 'Say something!', 'required');
function perform(&$page, $actionName)
echo "Submit successful!<br>\n<pre>\n";
var_dump($page->controller ->exportValues ());
$statemachine->addPage ($page1);
$statemachine->addPage ($page2a);
$statemachine->addPage ($page2b);
$statemachine->addPage ($page3);
// We actually add these handlers here for the sake of example
// They can be automatically loaded and added by the controller
// This is the action we should always define ourselves
Documentation generated on Mon, 11 Mar 2019 15:34:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|