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

Source for file regWizard.php

Documentation is available at regWizard.php

  1. <?php
  2. /**
  3.  * Example for HTML_QuickForm_Controller: registration wizard
  4.  *
  5.  * @version SVN: $Id: regWizard.php 289084 2009-10-02 06:53:09Z avb $
  6.  * @author  Bertrand Mansion <bmansion@mamasam.com>
  7.  * @ignore
  8.  */
  9.  
  10. require_once 'HTML/QuickForm/Controller.php';
  11. require_once 'HTML/QuickForm/Action/Display.php';
  12.  
  13. // Start the session
  14.  
  15.  
  16. // Rule for passwords comparison
  17. function comparePassword($fields)
  18. {
  19.     if (strlen($fields['password1']&& strlen($fields['password2']&&
  20.         $fields['password1'!= $fields['password2']{
  21.         return array('password1' => 'Passwords are not the same');
  22.     }
  23.     return true;
  24. }
  25.  
  26. // Class for first page : credentials
  27.  
  28. {
  29.  
  30.     function buildForm()
  31.     {
  32.         $this->_formBuilt = true;
  33.  
  34.         $this->addElement('header''credential_header''Your credentials');
  35.  
  36.         $this->addElement('text''username''Your email address :'array('size' => 30'maxlength' => 63));
  37.         $this->addElement('password''password1''Your password :'array('size' => 16'maxlength' => 32));
  38.         $this->addElement('password''password2''Confirm your password :'array('size' => 16'maxlength' => 32));
  39.  
  40.         $buttons[0=HTML_QuickForm::createElement('button''cancel''Cancel'array('onclick'=>"javascript:location.href='http://pear.php.net/package/HTML_QuickForm';"));
  41.         $buttons[1=HTML_QuickForm::createElement('submit'$this->getButtonName('next')'Next step >>');
  42.         $this->addGroup($buttons'buttons''''&nbsp'false);
  43.  
  44.         $this->addRule('username''Your email address is required''required'null'client');
  45.         $this->addRule('username''Your email address is incorrect''email'null'client');
  46.  
  47.         $this->addRule('password1''The password is required''required''''client');
  48.         $this->addRule('password1''The password is too short: 6 chars minimum''minlength'6'client');
  49.  
  50.         $this->addRule('password2''The password confirmation is required''required''''client');
  51.  
  52.         $this->addFormRule('comparePassword');
  53.  
  54.         $this->setDefaultAction('next');
  55.     }
  56. }
  57.  
  58. // Class for second page : user data
  59.  
  60. {
  61.  
  62.     function buildForm()
  63.     {
  64.         $this->_formBuilt = true;
  65.  
  66.         $this->addElement('header''data_header''Your personal data');
  67.  
  68.         $name[&HTML_QuickForm::createElement('text''first''Firstname'array('size' => 16'maxlength' => 63));
  69.         $name[&HTML_QuickForm::createElement('text''last''Lastname'array('size' => 16'maxlength' => 63));
  70.         $this->addGroup($name'name''Your name :'nullfalse);
  71.  
  72.         $this->addElement('text''company''Your company :',  array('size' => 30'maxlength' => 63));
  73.  
  74.         $this->addElement('text''address1''Your address :',  array('size' => 30'maxlength' => 63));
  75.         $this->addElement('text''address2''&nbsp;',  array('size' => 30'maxlength' => 63));
  76.  
  77.         $this->addElement('text''zip''Zip code :',  array('size' => 16'maxlength' => 16));
  78.         $this->addElement('text''city''City :',  array('size' => 30'maxlength' => 63));
  79.  
  80.         $countries = array('FR'=>'France''GE'=>'Germany''RU'=>'Russia''UK'=>'United Kingdom');
  81.         $this->addElement('select''country''Your country :'$countries);
  82.  
  83.         $this->addElement('text''phone''Phone number :',  array('size' => 16'maxlength' => 16));
  84.         $this->addElement('text''fax''Fax number :',  array('size' => 16'maxlength' => 16));
  85.  
  86.         $prevnext[=$this->createElement('submit',   $this->getButtonName('back')'<< Previous step');
  87.         $prevnext[=$this->createElement('submit',   $this->getButtonName('next')'Finish');
  88.         $this->addGroup($prevnext'buttons''''&nbsp;'false);
  89.  
  90.         $this->addGroupRule('name''First and last names are required''required');
  91.         $this->addRule('company''Company is required''required');
  92.         $this->addRule('address1''Address is required''required');
  93.         $this->addRule('city''City is required''required');
  94.  
  95.         $this->setDefaultAction('next');
  96.     }
  97. }
  98.  
  99. // Class for form rendering
  100.  
  101. {
  102.     function _renderForm(&$page)
  103.     {
  104.         $renderer =$page->defaultRenderer();
  105.  
  106.         $page->setRequiredNote('<font color="#FF0000">*</font> shows the required fields.');
  107.         $page->setJsWarnings('Those fields have errors :''Thanks for correcting them.');
  108.  
  109.         $renderer->setFormTemplate('<table width="450" border="0" cellpadding="3" cellspacing="2" bgcolor="#CCCC99"><form{attributes}>{content}</form></table>');
  110.         $renderer->setHeaderTemplate('<tr><td style="white-space:nowrap;background:#996;color:#ffc;" align="left" colspan="2"><b>{header}</b></td></tr>');
  111.         $renderer->setGroupTemplate('<table><tr>{content}</tr></table>''name');
  112.         $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');
  113.  
  114.         $page->accept($renderer);
  115.         echo $renderer->toHtml();
  116.     }
  117. }
  118.  
  119. // Class for form processing
  120.  
  121. {
  122.     function perform(&$page$actionName)
  123.     {
  124.         $values $page->controller->exportValues();
  125.         echo '<pre>';
  126.         var_dump($values);
  127.         echo '</pre>';
  128.     }
  129. }
  130.  
  131.  
  132. $wizard =new HTML_QuickForm_Controller('regWizard'true);
  133. $wizard->addPage(new Page_Account_Credentials('page1'));
  134. $wizard->addPage(new Page_Account_Information('page2'));
  135.  
  136. $wizard->setDefaults(array('country' => 'FR'));
  137.  
  138. $wizard->addAction('display'new ActionDisplay());
  139. $wizard->addAction('process'new ActionProcess());
  140.  
  141. $wizard->run();
  142. ?>

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