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

Source for file ITStatic_example.php

Documentation is available at ITStatic_example.php

  1. <?php
  2. /**
  3. * Example of usage for PEAR class HTML_QuickForm
  4. *
  5. @author      Bertrand Mansion <bmansion@mamasam.com>
  6. @version     2.0
  7. */
  8.  
  9. // $Id: ITStatic_example.php,v 1.4 2004/10/02 09:54:41 ths Exp $
  10.  
  11. require_once('HTML/QuickForm.php');
  12. require_once('HTML/QuickForm/Renderer/ITStatic.php');
  13. require_once('HTML/Template/ITX.php');
  14.  
  15.  
  16. // Form name will be used to find the placeholders.
  17.  
  18. $form = new HTML_QuickForm('form''POST');
  19.  
  20. // Fills with some defaults values
  21.  
  22. $defaultValues['company']  'Mamasam';
  23. $defaultValues['country']  = array();
  24. $defaultValues['name']     = array('first'=>'Bertrand''last'=>'Mansion');
  25. $defaultValues['phone']    = array('513''123''4567');
  26. $form->setDefaults($defaultValues);
  27.  
  28. // Hidden
  29.  
  30. $form->addElement('hidden''session''1234567890');
  31.  
  32. // Personal information
  33.  
  34. $form->addElement('header''personal''Personal Information');
  35.  
  36. $form->addElement('hidden''ihidTest''hiddenField');
  37. $form->addElement('text''email''Your email:');
  38. $form->addElement('password''pass''Your password:''size=10');
  39. $name['last'&HTML_QuickForm::createElement('text''first''First''size=10');
  40. $name['first'&HTML_QuickForm::createElement('text''last''Last''size=10');
  41. $form->addGroup($name'name''Name:'',&nbsp;');
  42. $areaCode &HTML_QuickForm::createElement('text'''null,'size=4 maxlength=3');
  43. $phoneNo1 &HTML_QuickForm::createElement('text'''null'size=4 maxlength=3');
  44. $phoneNo2 &HTML_QuickForm::createElement('text'''null'size=5 maxlength=4');
  45. $form->addGroup(array($areaCode$phoneNo1$phoneNo2)'phone''Telephone:''-');
  46.  
  47. // Company information
  48.  
  49. $form->addElement('header''company_info''Company Information');
  50.  
  51. $form->addElement('text''company''Company:''size=20');
  52.  
  53. $str[&HTML_QuickForm::createElement('text'''null'size=20');
  54. $str[&HTML_QuickForm::createElement('text'''null'size=20');
  55. $form->addGroup($str'street''Street:''<br />');
  56.  
  57. $addr['zip'&HTML_QuickForm::createElement('text''zip''Zip''size=6 maxlength=10');
  58. $addr['city'&HTML_QuickForm::createElement('text''city''City''size=15');
  59. $form->addGroup($addr'address''Zip, city:');
  60.  
  61. $select = array('' => 'Please select...''AU' => 'Australia''FR' => 'France''DE' => 'Germany''IT' => 'Italy');
  62. $form->addElement('select''country''Country:'$select);
  63.  
  64. $checkbox[&HTML_QuickForm::createElement('checkbox''A'null'A');
  65. $checkbox[&HTML_QuickForm::createElement('checkbox''B'null'B');
  66. $checkbox[&HTML_QuickForm::createElement('checkbox''C'null'C');
  67. $checkbox[&HTML_QuickForm::createElement('checkbox''D'null'D');
  68. $form->addGroup($checkbox'destination''Destination:'array('&nbsp;''<br />'));
  69.  
  70. // Other elements
  71.  
  72. $form->addElement('checkbox''news'''" Check this box if you don't want to receive our newsletter.");
  73.  
  74. $form->addElement('reset''reset''Reset');
  75. $form->addElement('submit''submit''Register');
  76.  
  77. // Adds some validation rules
  78.  
  79. $form->addRule('email''Email address is required''required');
  80. $form->addGroupRule('name''Name is required''required');
  81. $form->addRule('pass''Password must be between 8 to 10 characters''rangelength'array(810));
  82. $form->addRule('country''Country is a required field''required');
  83. $form->addGroupRule('destination''Please check at least two boxes''required'null2);
  84. $form->addGroupRule('phone''Please fill all phone fields''required');
  85. $form->addGroupRule('phone''Values must be numeric''numeric');
  86.  
  87. $AddrRules['zip'][0= array('Zip code is required''required');
  88. $AddrRules['zip'][1= array('Zip code is numeric only''numeric');
  89. $AddrRules['city'][0= array('City is required''required');
  90. $AddrRules['city'][1= array('City is letters only''lettersonly');
  91. $form->addGroupRule('address'$AddrRules);
  92.  
  93. // Tries to validate the form
  94. if ($form->validate()) {
  95.     // Form is validated, then freezes the data
  96.     $form->freeze();
  97. }
  98.  
  99. // Could be HTML_Template_Sigma('./templates')
  100. $tpl =new HTML_Template_ITX('./templates');
  101. $tpl->loadTemplateFile('it-static.html');
  102.  
  103. $renderer =new HTML_QuickForm_Renderer_ITStatic($tpl);
  104. $renderer->setRequiredTemplate('{label}<font color="red" size="1">*</font>');
  105. $renderer->setErrorTemplate('<font color="orange" size="1">{error}</font><br />{html}');
  106.  
  107. $form->accept($renderer);
  108.  
  109. $tpl->show();
  110.  
  111. ?>

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