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

Source for file contact_dhtmlrules.php

Documentation is available at contact_dhtmlrules.php

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  2.     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html>
  4.   <head>
  5.     <style type="text/css">
  6. /* this style is used only for this example to make it look better */
  7. /* only the second block (it's the same as in data/stylesheet.css) is relevant */
  8. body {
  9.     margin-left: 10px;
  10.     font-family: Arial,sans-serif;
  11.     font-size: small;
  12. }
  13.     </style>
  14.     <style type="text/css">
  15. form {
  16.     margin: 0;
  17.     padding: 0;
  18.     min-width: 500px;
  19.     max-width: 600px;
  20.     width: 560px;
  21. }
  22. form fieldset {
  23.     clear: both;
  24.     float: left;
  25.     border: 0;
  26.     margin: 0;
  27.     width: 100%;
  28. }
  29. form fieldset.hidden {
  30.     border: 0;
  31. }
  32. form fieldset legend {
  33.     white-space: nowrap;
  34.     background-color: #CCCCCC;
  35.     font-weight: bold;
  36.     width: 100%;
  37.     padding: 1px;
  38.     display: block;
  39. }
  40. form fieldset ol {
  41.     margin: 0;
  42.     padding: 0;
  43. }
  44. form fieldset li {
  45.     display: block;
  46.     list-style: none;
  47.     margin: 0;
  48.     clear: both;
  49. }
  50. form label {
  51.     margin: 0 0 0 5px;
  52. }
  53. form label.element {
  54.     display: block;
  55.     float: left;
  56.     width: 150px;
  57.     padding: 0;
  58.     margin: 5px 0 0 0;
  59.     font-weight: bold;
  60.     text-align: right;
  61. }
  62. form input, form textarea, form select {
  63.     width: auto;
  64. }
  65. form textarea {
  66.     overflow: auto;
  67. }
  68. form br {
  69.     clear: left;
  70. }
  71. form div.element {
  72.     display: inline;
  73.     float: left;
  74.     margin: 5px 0 0 10px;
  75.     padding: 0;
  76. }
  77. form li.reqnote {
  78.     font-size: 80%; 
  79.     margin: 5px 0 0 10px;
  80. }
  81. form span.error, form span.required {
  82.     color: red;
  83. }
  84. form div.error {
  85.     border: 1px solid red;
  86.     padding: 5px;
  87. }
  88.     </style>
  89.     <title>HTML_QuickForm_DHTMLRulesTableless example</title>
  90.   </head>
  91.   <body>
  92. <?php
  93.  
  94. require_once 'HTML/QuickForm.php';
  95. require_once 'HTML/QuickForm/DHTMLRulesTableless.php';
  96. require_once 'HTML/QuickForm/Renderer/Tableless.php';
  97.  
  98. $form = new HTML_QuickForm_DHTMLRulesTableless('contact'nullnullnullnulltrue);
  99. $form->removeAttribute('name');  // for XHTML validity
  100.  
  101. $form->addElement('text''fieldsetlesselement''Element before header:'array('style' => 'width: 300px;'));
  102.  
  103. $form->addElement('header''header''Tableless renderer example (using DHTMLRules)');
  104.  
  105. $id['lastname'&HTML_QuickForm::createElement('text''lastname''Name'array('size' => 30))
  106. $id['code'&HTML_QuickForm::createElement('text''code''Code'array('size' => 5'maxlength' => 4))
  107. $form->addGroup($id'id''ID:'',&nbsp')
  108.  
  109. $form->addGroupRule('id'array
  110.     'lastname' => array
  111.         array('Name is required''required'null'client')
  112.         array('Name is letters only''lettersonly'null'client'
  113.     )
  114.     'code'     => array
  115.         array('Code must be numeric''numeric'null'client'
  116.     
  117. ));
  118.  
  119. $form->addElement('text''name''Your name:'array('style' => 'width: 300px;'));
  120. $form->addElement('text''email''Your email:'array('style' => 'width: 300px;'));
  121. $form->addElement('text''emptylabel'''array('style' => 'width: 300px;'));
  122. $form->addElement('text'null'Element without name:'array('style' => 'width: 300px;'));
  123. $form->addElement('text''''Element with empty name:'array('style' => 'width: 300px;'));
  124. $form->addElement('text''subject''Your subject:'array('style' => 'width: 300px;'));
  125. $form->addElement('checkbox''single''Checkbox example:'' Check me if you agree to receive spam ;-)');
  126.  
  127. $form->addElement('header''header2''Some groups');
  128.  
  129. $radio = array();
  130. $radio[&HTML_QuickForm::createElement('radio''country'null'France''france');
  131. $radio[&HTML_QuickForm::createElement('radio''country'null'Germany''germany');
  132. $radio[&HTML_QuickForm::createElement('radio''country'null'Austria''austria');
  133. $radio[&HTML_QuickForm::createElement('radio''country'null'Other''other');
  134. $form->addGroup($radio'group1''Choose a country:'' ');
  135. $form->addGroupRule('group1''Please select a country''required'null1client)
  136.  
  137. $form->addElement('date''date''Date:'array('format' => 'Y-m-d H:i''optionIncrement' => array('i' => 5)));
  138.  
  139. $checkbox = array();
  140. $checkbox[&HTML_QuickForm::createElement('checkbox''A1'null'France');
  141. $checkbox[&HTML_QuickForm::createElement('checkbox''B1'null'Germany');
  142. $checkbox[&HTML_QuickForm::createElement('checkbox''C1'null'Austria');
  143. $checkbox[&HTML_QuickForm::createElement('checkbox''D1'null'Other');
  144. $form->addGroup($checkbox'group2''Choose a country:'' ');
  145.  
  146. $checkbox = array();
  147. $checkbox[&HTML_QuickForm::createElement('checkbox''A2'null'France');
  148. $checkbox[&HTML_QuickForm::createElement('checkbox''B2'null'Germany');
  149. $checkbox[&HTML_QuickForm::createElement('checkbox''C2'null'Austria');
  150. $checkbox[&HTML_QuickForm::createElement('checkbox''D2'null'Other');
  151. $form->addGroup($checkbox'group3''Choose a country:''<br />');
  152.  
  153. $form->addElement('header''header3''The third fieldset');
  154.  
  155. $main[0'Pop';
  156. $main[1'Rock';
  157. $main[2'Classical';
  158.  
  159. $secondary[0][0'Belle &amp; Sebastian';
  160. $secondary[0][1'Elliot Smith';
  161. $secondary[0][2'Beck';
  162. $secondary[1][3'Noir Desir';
  163. $secondary[1][4'Violent Femmes';
  164. $secondary[2][5'Wagner';
  165. $secondary[2][6'Mozart';
  166. $secondary[2][7'Beethoven';
  167.  
  168. $select =$form->addElement('hierselect''music''Please select:');
  169. $select->setOptions(array($main$secondary));
  170.  
  171. $form->addElement('textarea''message''Your message:'array('style' => 'width: 300px;''cols' => 50'rows' => '7'));
  172. $form->addElement('submit''submit''Submit');
  173.  
  174. $form->addRule('name''Please enter your name''required'null'client');
  175. $form->addRule('email''Please enter your email address.''required'null'client');
  176. $form->addRule('email''Please enter a valid email address.''email'null'client');
  177. $form->addRule('subject''Please enter a subject.''required'null'client');
  178. $form->addRule('message''Please enter a message.''required'null'client');
  179.  
  180. if ($form->isSubmitted(&& $form->validate()) {
  181.   $data $form->exportValues();
  182.   // do something with $data
  183.   echo "<p>Thank you</p>\n";
  184. }
  185. else {
  186.   $form->getValidationScript();
  187.   $renderer =new HTML_QuickForm_Renderer_Tableless();
  188.   $renderer->addStopFieldsetElements('submit');
  189.   $form->accept($renderer);
  190.   echo $renderer->toHtml();
  191. }
  192.  
  193. ?>
  194.   </body>
  195. </html>

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