Source for file tabbed.php
Documentation is available at tabbed.php
* Usage example for HTML_QuickForm2_Controller: tabbed form
* @author Alexey Borzov <avb@php.net>
* @author Bertrand Mansion <php@mamasam.com>
require_once 'HTML/QuickForm2.php';
require_once 'HTML/QuickForm2/Controller.php';
require_once 'HTML/QuickForm2/Renderer.php';
// Load some default action handlers
require_once 'HTML/QuickForm2/Controller/Action/Submit.php';
require_once 'HTML/QuickForm2/Controller/Action/Jump.php';
require_once 'HTML/QuickForm2/Controller/Action/Direct.php';
require_once 'HTML/QuickForm2/Controller/Action/Display.php';
// Start the session, form-page values will be kept there
$tabGroup = $this->form->addElement ('group')->setSeparator (' ')
array ('class' => 'flat', 'value' => ucfirst($pageId)) +
($page === $this? array ('disabled' => 'disabled'): array ()));
array ('value' => 'Big Red Button', 'class' => 'bigred'));
$fs = $this->form->addElement ('fieldset')->setLabel ('Foo page');
$radioGroup = $fs->addElement ('group')->setLabel ('Do you want this feature?')
->setSeparator ('<br />');
$radioGroup->addElement ('radio', 'iradYesNoMaybe', array ('value' => 'Y'), array ('content' => 'Yes'));
$radioGroup->addElement ('radio', 'iradYesNoMaybe', array ('value' => 'N'), array ('content' => 'No'));
$radioGroup->addElement ('radio', 'iradYesNoMaybe', array ('value' => 'M'), array ('content' => 'Maybe'));
$fs->addElement ('text', 'tstText', array ('size'=>20 , 'maxlength'=>50 ))
->setLabel ('Why do you want it?');
$radioGroup->addRule ('required', 'Check a radiobutton');
$fs = $this->form->addElement ('fieldset')->setLabel ('Bar page');
// XXX: no date element yet
$dateGroup = $fs->addElement ('group', 'favDate')->setLabel ('Favourite date:')
for ($i = 1 , $doptions = array (); $i <= 31; $i++ ) {
$doptions[$i] = sprintf('%02d', $i);
$dateGroup->addElement ('select', 'd')->loadOptions ($doptions);
$dateGroup->addElement ('select', 'M')->loadOptions (array (
1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 5 => 'June',
7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'
for ($i = 1950 , $yoptions = array (); $i <= date('Y'); $i++ ) {
$dateGroup->addElement ('select', 'Y')->loadOptions ($yoptions);
$checkGroup = $fs->addElement ('group', 'favLetter')->setLabel ('Favourite letters:')
->setSeparator (array (' ', '<br />'));
foreach (array ('A', 'B', 'C', 'D', 'X', 'Y', 'Z') as $letter) {
$checkGroup->addElement ('checkbox', $letter)->setContent ($letter);
$fs = $this->form->addElement ('fieldset')->setLabel ('Baz page');
$poem = $fs->addElement ('textarea', 'textPoetry', array ('rows' => 5 , 'cols' => 40 ))
->setLabel ('Recite a poem:');
$fs->addElement ('textarea', 'textOpinion', array ('rows' => 5 , 'cols' => 40 ))
->setLabel ('Did you like this demo?');
$poem->addRule ('required', 'Pretty please!');
protected function renderForm(HTML_QuickForm2 $form)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
/* Set up custom font and form width */
font-family: Arial,sans-serif;
.quickform input.bigred {font-weight: bold; background: #FF6666;}
.quickform input.flat {border-style: solid; border-width: 2px; border-color: #000000;}
/* Use default styles included with the package */
if ('@data_dir@' != '@' . 'data_dir@') {
$filename = '@data_dir@/HTML_QuickForm2/quickform.css';
<title>HTML_QuickForm2 simple controller example</title>
$renderer->setTemplateForId ('tabs', '<div style="float: right;">{content}</div>');
echo $form->render ($renderer);
public function perform(HTML_QuickForm2_Controller_Page $page, $name)
echo "Submit successful!<br>\n<pre>\n";
var_dump($page->getController ()->getValue ());
// These actions manage going directly to the pages with the same name
// 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
// We redefine 'display' handler to use the proper stylesheets
'favLetter' => array ('A' => true , 'Z' => true ),
'favDate' => array ('d' => 1 , 'M' => 1 , 'Y' => 2001 ),
'textOpinion' => 'Yes, it rocks!'
Documentation generated on Wed, 10 Apr 2019 08:56:11 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|