Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Fabio Ambrosanio  >  HTML_QuickForm_Wizard  >  tests/test.php  >  Download  
File: tests/test.php
Role: Example script
Content type: text/plain
Description: Example of use
Class: HTML_QuickForm_Wizard
Display and process wizard-like multipage forms
Author: By
Last change:
Date: 2007-03-16 03:24
Size: 3,229 bytes
 

Contents

Class file image Download
<?php
require_once("../Wizard.php");


class 
PageSecond extends HTML_QuickForm_Page
{
    function 
buildForm()
    {
        
$this->_formBuilt true;

        
$this->addElement('header',     null'Wizard page 2 of 3 (B)');

        
$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):'',&nbsp;');

        
$prevnext[] =& $this->createElement('submit',   $this->getButtonName('back'), '<< Back');
        
$prevnext[] =& $this->createElement('submit',   $this->getButtonName('next'), 'Next >>');
        
$this->addGroup($prevnextnull'''&nbsp;'false);

        
$this->addGroupRule('name', array('last' => array(array('Last name is required''required'))));

        
$this->setDefaultAction('next');
    }
}


class 
PageSecondBis extends HTML_QuickForm_Page
{
    function 
buildForm()
    {
        
$this->_formBuilt true;

        
$this->addElement('header',     null'Wizard page 2 bis of 3 (C)');

        
$this->addElement('textarea',   'why''Why are you not sure?:', array('rows' => 5'cols' => 40));

        
$prevnext[] =& $this->createElement('submit',   $this->getButtonName('back'), '<< Back');
        
$prevnext[] =& $this->createElement('submit',   $this->getButtonName('next'), 'Next >>');
        
$this->addGroup($prevnextnull'''&nbsp;'false);

        
$this->addRule('why''Say something!''required');

        
$this->setDefaultAction('next');
    }
}


class 
PageThird extends HTML_QuickForm_Page
{
    function 
buildForm()
    {
        
$this->_formBuilt true;

        
$this->addElement('header',     null'Wizard page 3 of 3 (D)');

        
$this->addElement('textarea',   'itxaTest''Parting words:', array('rows' => 5'cols' => 40));

        
$prevnext[] =& $this->createElement('submit',   $this->getButtonName('back'), '<< Back');
        
$prevnext[] =& $this->createElement('submit',   $this->getButtonName('next'), 'Finish');
        
$this->addGroup($prevnextnull'''&nbsp;'false);

        
$this->addRule('itxaTest''Say something!''required');

        
$this->setDefaultAction('next');
    }
}



class 
ActionProcess extends HTML_QuickForm_Action
{
    function 
perform(&$page$actionName)
    {
        echo 
"Submit successful!<br>\n<pre>\n";
        
var_dump($page->controller->exportValues());
        echo 
"\n</pre>\n";

        
$page->controller->reset();
    }
}


function 
myInputProducer(&$data)
{
    
$input = array();

    if (
$data['values']['A']['iradYesNo'] == 'Y') {
        
array_push($input'sure');
    }

    return empty(
$input) ? '' $input;
}



// Start the session, form-page values will be kept there
session_start();

$wizard = new HTML_QuickForm_Wizard($_SERVER['PHP_SELF'], true);

//include_once("fsm.php");
//$wizard->setFSM($fsm);
$wizard->fromXML('test.xml'true);
print 
"<pre>"print_r($wizard->getFSM()); print "</pre>";

$wizard->addAction('process', new ActionProcess());
$wizard->setInputProducer('myInputProducer');

if (isset(
$_REQUEST[reset])) $wizard->reset();
$data =& $wizard->container(isset($_REQUEST['new']));

$wizard->run();
?>