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

Source for file groups.php

Documentation is available at groups.php

  1. <?php
  2. /**
  3. * Examples of usage for grouped elements in HTML_QuickForm
  4. *
  5. * $Id: groups.php,v 1.1 2003/12/20 21:05:32 avb Exp $
  6. @author      Bertrand Mansion <bmansion@mamasam.com>
  7. @author      Alexey Borzov <avb@php.net>
  8. @version     3.2
  9. */
  10.  
  11. require_once 'HTML/QuickForm.php';
  12.  
  13. $form =new HTML_QuickForm('frmGroups');
  14. $form->setDefaults(array(
  15.     'id'        => array('lastname' => 'Mamasam''code' => '1234'),
  16.     'phoneNo'   => array('513''123''3456'),
  17.     'ichkABC'   => array('A'=>true)
  18. ));
  19.  
  20. $renderer =$form->defaultRenderer();
  21.  
  22. // Setting templates for form and headers
  23. $renderer->setFormTemplate("<form{attributes}>\n<table width=\"450\" border=\"0\" cellpadding=\"3\" cellspacing=\"2\" bgcolor=\"#CCCC99\">\n{content}\n</table>\n</form>");
  24. $renderer->setHeaderTemplate("\t<tr>\n\t\t<td style=\"white-space:nowrap;background:#996;color:#ffc;\" align=\"left\" colspan=\"2\"><b>{header}</b></td>\n\t</tr>");
  25.  
  26. // Setting a special template for id element
  27. $renderer->setGroupTemplate('<table><tr>{content}</tr></table>''id');
  28. $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>''id');
  29.  
  30.  
  31. $form->addElement('header''''Tests on grouped elements');
  32.  
  33. // Creates a group of text inputs with templates
  34. $id['lastname'&HTML_QuickForm::createElement('text''lastname''Name'array('size' => 30));
  35. $id['code'&HTML_QuickForm::createElement('text''code''Code'array('size' => 5'maxlength' => 4));
  36. $form->addGroup($id'id''ID:'',&nbsp');
  37.  
  38. // Add a complex rule for id element
  39. $form->addGroupRule('id'array(
  40.     'lastname' => array(
  41.         array('Name is required''required'null'client'),
  42.         array('Name is letters only''lettersonly'null'client')
  43.     ),
  44.     'code'     => array(
  45.         array('Code must be numeric''numeric'null'client')
  46.     )
  47. ));
  48.  
  49.  
  50. // Creates a group of text inputs
  51. $areaCode &HTML_QuickForm::createElement('text'''nullarray('size' => 4'maxlength' => 3));
  52. $phoneNo1 &HTML_QuickForm::createElement('text'''nullarray('size' => 4'maxlength' => 3));
  53. $phoneNo2 &HTML_QuickForm::createElement('text'''nullarray('size' => 5'maxlength' => 4));
  54. $form->addGroup(array($areaCode$phoneNo1$phoneNo2)'phoneNo''Telephone:''-');
  55.  
  56. // Adds validation rules for groups
  57. $form->addGroupRule('phoneNo''Please fill all phone fields''required'null3'client');
  58. $form->addGroupRule('phoneNo''Values must be numeric''numeric'null3'client');
  59.  
  60. // Creates a checkboxes group using an array of separators
  61. $checkbox[&HTML_QuickForm::createElement('checkbox''A'null'A');
  62. $checkbox[&HTML_QuickForm::createElement('checkbox''B'null'B');
  63. $checkbox[&HTML_QuickForm::createElement('checkbox''C'null'C');
  64. $checkbox[&HTML_QuickForm::createElement('checkbox''D'null'D');
  65. $form->addGroup($checkbox'ichkABC''ABCD:'array('&nbsp;''<br />'));
  66.  
  67. // At least one element is required
  68. $form->addGroupRule('ichkABC''Please check at least two boxes''required'null2'client'true);
  69.  
  70. // Creates a standard radio buttons group
  71. $radio[&HTML_QuickForm::createElement('radio'nullnull'Yes''Y');
  72. $radio[&HTML_QuickForm::createElement('radio'nullnull'No''N');
  73. $form->addGroup($radio,  'iradYesNo''Yes/No:');
  74.  
  75. // Validate the radio buttons
  76. $form->addRule('iradYesNo''Check Yes or No''required'null'client');
  77.  
  78. // Creates a group of buttons to be displayed at the bottom of the form
  79. $buttons[=$form->createElement('submit'null'Submit');
  80. $buttons[=$form->createElement('reset'null'Reset');
  81. $buttons[=$form->createElement('checkbox''clientSide'null'use client-side validation'array('checked' => 'checked''onclick' => "if (this.checked) {this.form.onsubmit = validate_" $form->getAttribute('id'";} else {this.form.onsubmit = null;}"));
  82. $form->addGroup($buttons);
  83.  
  84.  
  85. // Tries to validate the form
  86. if ($form->validate()) {
  87.     // Form is validated, then processes the data
  88.     $form->freeze();
  89.     $form->process('var_dump');
  90.     echo "\n<HR>\n";
  91. }
  92. $form->display();
  93.  
  94. ?>

Documentation generated on Mon, 11 Mar 2019 13:52:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.