Source for file regWizard.php
Documentation is available at regWizard.php
* Example for HTML_QuickForm_Controller: registration wizard
* @version SVN: $Id: regWizard.php 289084 2009-10-02 06:53:09Z avb $
* @author Bertrand Mansion <bmansion@mamasam.com>
require_once 'HTML/QuickForm/Controller.php';
require_once 'HTML/QuickForm/Action/Display.php';
// Rule for passwords comparison
if (strlen($fields['password1']) && strlen($fields['password2']) &&
$fields['password1'] != $fields['password2']) {
return array ('password1' => 'Passwords are not the same');
// Class for first page : credentials
$this->_formBuilt = true;
$this->addElement ('header', 'credential_header', 'Your credentials');
$this->addElement ('text', 'username', 'Your email address :', array ('size' => 30 , 'maxlength' => 63 ));
$this->addElement ('password', 'password1', 'Your password :', array ('size' => 16 , 'maxlength' => 32 ));
$this->addElement ('password', 'password2', 'Confirm your password :', array ('size' => 16 , 'maxlength' => 32 ));
$buttons[0 ] = & HTML_QuickForm ::createElement ('button', 'cancel', 'Cancel', array ('onclick'=> "javascript:location.href='http://pear.php.net/package/HTML_QuickForm';"));
$buttons[1 ] = & HTML_QuickForm ::createElement ('submit', $this->getButtonName('next'), 'Next step >>');
$this->addGroup ($buttons, 'buttons', '', ' ', false );
$this->addRule ('username', 'Your email address is required', 'required', null , 'client');
$this->addRule ('username', 'Your email address is incorrect', 'email', null , 'client');
$this->addRule ('password1', 'The password is required', 'required', '', 'client');
$this->addRule ('password1', 'The password is too short: 6 chars minimum', 'minlength', 6 , 'client');
$this->addRule ('password2', 'The password confirmation is required', 'required', '', 'client');
$this->addFormRule ('comparePassword');
// Class for second page : user data
$this->_formBuilt = true;
$this->addElement ('header', 'data_header', 'Your personal data');
$name[] = &HTML_QuickForm ::createElement ('text', 'first', 'Firstname', array ('size' => 16 , 'maxlength' => 63 ));
$name[] = &HTML_QuickForm ::createElement ('text', 'last', 'Lastname', array ('size' => 16 , 'maxlength' => 63 ));
$this->addGroup ($name, 'name', 'Your name :', null , false );
$this->addElement ('text', 'company', 'Your company :', array ('size' => 30 , 'maxlength' => 63 ));
$this->addElement ('text', 'address1', 'Your address :', array ('size' => 30 , 'maxlength' => 63 ));
$this->addElement ('text', 'address2', ' ', array ('size' => 30 , 'maxlength' => 63 ));
$this->addElement ('text', 'zip', 'Zip code :', array ('size' => 16 , 'maxlength' => 16 ));
$this->addElement ('text', 'city', 'City :', array ('size' => 30 , 'maxlength' => 63 ));
$countries = array ('FR'=> 'France', 'GE'=> 'Germany', 'RU'=> 'Russia', 'UK'=> 'United Kingdom');
$this->addElement ('select', 'country', 'Your country :', $countries);
$this->addElement ('text', 'phone', 'Phone number :', array ('size' => 16 , 'maxlength' => 16 ));
$this->addElement ('text', 'fax', 'Fax number :', array ('size' => 16 , 'maxlength' => 16 ));
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('back'), '<< Previous step');
$prevnext[] = & $this->createElement ('submit', $this->getButtonName('next'), 'Finish');
$this->addGroup ($prevnext, 'buttons', '', ' ', false );
$this->addGroupRule ('name', 'First and last names are required', 'required');
$this->addRule ('company', 'Company is required', 'required');
$this->addRule ('address1', 'Address is required', 'required');
$this->addRule ('city', 'City is required', 'required');
// Class for form rendering
function _renderForm (&$page)
$renderer = & $page->defaultRenderer ();
$page->setRequiredNote ('<font color="#FF0000">*</font> shows the required fields.');
$page->setJsWarnings ('Those fields have errors :', 'Thanks for correcting them.');
$renderer->setFormTemplate ('<table width="450" border="0" cellpadding="3" cellspacing="2" bgcolor="#CCCC99"><form{attributes}>{content}</form></table>');
$renderer->setHeaderTemplate ('<tr><td style="white-space:nowrap;background:#996;color:#ffc;" align="left" colspan="2"><b>{header}</b></td></tr>');
$renderer->setGroupTemplate ('<table><tr>{content}</tr></table>', 'name');
$renderer->setGroupElementTemplate ('<td>{element}<br /><span style="font-size:10px;"><!-- BEGIN required --><span style="color: #f00">*</span><!-- END required --><span style="color:#996;">{label}</span></span></td>', 'name');
$page->accept ($renderer);
echo $renderer->toHtml ();
// Class for form processing
function perform(&$page, $actionName)
$values = $page->controller ->exportValues ();
$wizard->setDefaults (array ('country' => 'FR'));
Documentation generated on Mon, 11 Mar 2019 15:34:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|