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

Source for file ITDynamic_example2.php

Documentation is available at ITDynamic_example2.php

  1. <?php
  2. /**
  3. *Example of usage for HTML_QuickForm with ITDynamic renderer (2-column layout)
  4. *
  5. @author      Adam Daniel <adaniel1@eesus.jnj.com>
  6. @author      Bertrand Mansion <bmansion@mamasam.com>
  7. @author      Alexey Borzov <borz_off@cs.msu.su>
  8. @version     3.0
  9. */
  10. require_once 'HTML/QuickForm.php';
  11. require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
  12. // can use either HTML_Template_Sigma or HTML_Template_ITX
  13. require_once 'HTML/Template/ITX.php';
  14. //require_once 'HTML/Template/Sigma.php';
  15.  
  16. $form = new HTML_QuickForm('frmTest''POST');
  17.  
  18. // Fills with some defaults values
  19. $defaultValues['company']  'Mamasam';
  20. $defaultValues['country']  = array();
  21. $defaultValues['name']      = array('first'=>'Alexey''last'=>'Borzov');
  22. $defaultValues['phone']   = array('513''123''4567');
  23. $form->setDefaults($defaultValues);
  24.  
  25. // Hidden
  26. $form->addElement('hidden''session''1234567890');
  27. $form->addElement('hidden''timer''12345');
  28. $form->addElement('hidden''ihidTest''hiddenField');
  29.  
  30. // Personal information
  31. $form->addElement('header''personal_info''Personal Information');
  32.  
  33. $name['last'&HTML_QuickForm::createElement('text''first''First''size=10');
  34. $name['first'&HTML_QuickForm::createElement('text''last''Last''size=10');
  35. $form->addGroup($name'name''Name:'',&nbsp;');
  36.  
  37. $areaCode &HTML_QuickForm::createElement('text'''null,'size=4 maxlength=3');
  38. $phoneNo1 &HTML_QuickForm::createElement('text'''null'size=4 maxlength=3');
  39. $phoneNo2 &HTML_QuickForm::createElement('text'''null'size=5 maxlength=4');
  40. $form->addGroup(array($areaCode$phoneNo1$phoneNo2)'phone''Telephone:''-');
  41.  
  42. $form->addElement('text''email''Your email:');
  43.  
  44. $form->addElement('password''pass''Your password:''size=10');
  45.  
  46. // to finish the first column:
  47. $form->addElement('static'nullnull'first column');
  48.  
  49.  
  50. // Company information
  51. $form->addElement('header''company_info''Company Information');
  52.  
  53. $form->addElement('text''company''Company:''size=20');
  54.  
  55. $str[&HTML_QuickForm::createElement('text'''null'size=20');
  56. $str[&HTML_QuickForm::createElement('text'''null'size=20');
  57. $form->addGroup($str'street''Street:''<br />');
  58.  
  59.  
  60. $addr['zip'&HTML_QuickForm::createElement('text''zip''Zip''size=6 maxlength=10');
  61. $addr['city'&HTML_QuickForm::createElement('text''city''City''size=15');
  62. $form->addGroup($addr'address''Zip, city:');
  63.  
  64. $select = array('' => 'Please select...''AU' => 'Australia''FR' => 'France''DE' => 'Germany''IT' => 'Italy');
  65. $form->addElement('select''country''Country:'$select);
  66.  
  67. // Creates a checkboxes group using an array of separators
  68. $checkbox[&HTML_QuickForm::createElement('checkbox''A'null'A');
  69. $checkbox[&HTML_QuickForm::createElement('checkbox''B'null'B');
  70. $checkbox[&HTML_QuickForm::createElement('checkbox''C'null'C');
  71. $checkbox[&HTML_QuickForm::createElement('checkbox''D'null'D');
  72. $form->addGroup($checkbox'destination''Destination:'array('&nbsp;''<br />'));
  73.  
  74. // to finish the second column:
  75. $form->addElement('static'nullnull'second column');
  76.  
  77. // can't render these elements properly, so they are in the template
  78. //$form->addElement('reset', 'reset', 'Reset');
  79. //$form->addElement('submit', 'submit', 'Register');
  80.  
  81. // Adds some validation rules
  82. $form->addRule('email''Email address is required''required');
  83. $form->addGroupRule('name''Name is required''required');
  84. $form->addRule('pass''Password must be between 8 to 10 characters''rangelength'array(810));
  85. $form->addRule('country''Country is a required field''required');
  86. $form->addGroupRule('destination''Please check at least two boxes''required'null2);
  87. $form->addGroupRule('phone''Please fill all phone fields''required');
  88. $form->addGroupRule('phone''Values must be numeric''numeric');
  89.  
  90.  
  91. $AddrRules['zip'][0= array('Zip code is required''required');
  92. $AddrRules['zip'][1= array('Zip code is numeric only''numeric');
  93. $AddrRules['city'][0= array('City is required''required');
  94. $AddrRules['city'][1= array('City is letters only''lettersonly');
  95. $form->addGroupRule('address'$AddrRules);
  96.  
  97. // Tries to validate the form
  98. if ($form->validate()) {
  99.     // Form is validated, then freezes the data
  100.     $form->freeze();
  101. }
  102.  
  103.  
  104. // can use either HTML_Template_Sigma or HTML_Template_ITX
  105. $tpl =new HTML_Template_ITX('./templates');
  106. // $tpl =& new HTML_Template_Sigma('./templates');
  107.  
  108. $tpl->loadTemplateFile('it-dynamic-2.html');
  109.  
  110. $renderer =new HTML_QuickForm_Renderer_ITDynamic($tpl);
  111. $renderer->setElementBlock(array(
  112.     'name'     => 'qf_group_table',
  113.     'address'  => 'qf_group_table'
  114. ));
  115.  
  116. $form->accept($renderer);
  117.  
  118. $tpl->show();
  119. ?>

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