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

Source for file basic-elements.php

Documentation is available at basic-elements.php

  1. <?php
  2. /**
  3.  * Usage example for HTML_QuickForm2 package: basic elements
  4.  *
  5.  * $Id: basic-elements.php 288268 2009-09-11 13:50:48Z avb $
  6.  */ 
  7. ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  9.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  10. <html>
  11.   <head>
  12.     <style type="text/css">
  13. /* Set up custom font and form width */
  14. body {
  15.     margin-left: 10px;
  16.     font-family: Arial,sans-serif;
  17.     font-size: small;
  18. }
  19.  
  20. .quickform {
  21.     min-width: 500px;
  22.     max-width: 600px;
  23.     width: 560px;
  24. }
  25.  
  26. /* Use default styles included with the package */
  27.  
  28. <?php
  29. if ('@data_dir@' != '@' 'data_dir@'{
  30.     $filename '@data_dir@/HTML_QuickForm2/data/quickform.css';
  31. else {
  32.     $filename dirname(dirname(dirname(__FILE__))) '/data/quickform.css';
  33. }
  34. readfile($filename);
  35. ?>
  36.     </style>
  37.     <title>HTML_QuickForm2 basic elements example</title>
  38.   </head>
  39.   <body>
  40. <?php
  41.  
  42. $options = array(
  43.     'a' => 'Letter A''b' => 'Letter B''c' => 'Letter C',
  44.     'd' => 'Letter D''e' => 'Letter E''f' => 'Letter F'
  45. );
  46.  
  47. require_once 'HTML/QuickForm2.php';
  48.  
  49. $form = new HTML_QuickForm2('elements');
  50.  
  51. // data source with default values:
  52. $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
  53.     'textTest'        => 'Some text',
  54.     'areaTest'        => "Some text\non multiple lines",
  55.     'userTest'        => 'luser',
  56.     'selSingleTest'   => 'f',
  57.     'selMultipleTest' => array('b''c'),
  58.     'boxTest'         => '1',
  59.     'radioTest'       => '2'
  60. )));
  61.  
  62. // text input elements
  63. $fsText $form->addElement('fieldset')->setLabel('Text boxes');
  64. $fsText->addElement(
  65.     'text''textTest'array('style' => 'width: 300px;')array('label' => 'Test Text:'
  66. );
  67. $fsText->addElement(
  68.     'password''pwdTest'array('style' => 'width: 300px;')array('label' => 'Test Password:'
  69. );
  70. $area $fsText->addElement(
  71.     'textarea''areaTest'array('style' => 'width: 300px;''cols' => 50'rows' => 7),
  72.     array('label' => 'Test Textarea:')
  73. );
  74.  
  75. $fsNested $form->addElement('fieldset')->setLabel('Nested fieldset');
  76. $fsNested->addElement(
  77.     'text''userTest'array('style' => 'width: 200px')array('label' => 'Username:')
  78. );
  79. $fsNested->addElement(
  80.     'password''passTest'array('style' => 'width: 200px')array('label' => 'Password:')
  81. );
  82. // Now we move the fieldset into another fieldset!
  83. $fsText->insertBefore($fsNested$area);
  84.  
  85.  
  86. // selects
  87. $fsSelect $form->addElement('fieldset')->setLabel('Selects');
  88. $fsSelect->addElement(
  89.     'select''selSingleTest'nullarray('options' => $options'label' => 'Single select:')
  90. );
  91. $fsSelect->addElement(
  92.     'select''selMultipleTest'array('multiple' => 'multiple''size' => 4),
  93.     array('options' => $options'label' => 'Multiple select:')
  94. );
  95.  
  96. // checkboxes and radios
  97. $fsCheck $form->addElement('fieldset')->setLabel('Checkboxes and radios');
  98. $fsCheck->addElement(
  99.     'checkbox''boxTest'nullarray('content' => 'check me''label' => 'Test Checkbox:')
  100. );
  101. $fsCheck->addElement(
  102.     'radio''radioTest'array('value' => 1)array('content' => 'select radio #1''label' => 'Test radio:')
  103. );
  104. $fsCheck->addElement(
  105.     'radio''radioTest'array('value' => 2)array('content' => 'select radio #2''label' => '(continued)')
  106. );
  107.  
  108. // buttons
  109. $fsButton $form->addElement('fieldset')->setLabel('Buttons');
  110. $testReset $fsButton->addElement(
  111.     'reset''testReset'array('value' => 'This is a reset button')
  112. );
  113. $fsButton->addElement(
  114.     'inputbutton''testInputButton',
  115.     array('value' => 'Click this button''onclick' => "alert('This is a test.');")
  116. );
  117. $fsButton->addElement(
  118.     'button''testButton'array('onclick' => "alert('Almost nothing');"'type' => 'button')
  119.     array('content' => '<img src="http://pear.php.net/gifs/pear-icon.gif" '.
  120.         'width="32" height="32" alt="pear" />This button does almost nothing')
  121. );
  122. // submit buttons in nested fieldset
  123. $fsSubmit $fsButton->addElement('fieldset')->setLabel('These buttons can submit the form');
  124. $fsSubmit->addElement(
  125.     'submit''testSubmit'array('value' => 'Test Submit')
  126. );
  127. $fsSubmit->addElement(
  128.     'button''testSubmitButton'array('type' => 'submit')
  129.      array('content' => '<img src="http://pear.php.net/gifs/pear-icon.gif" '.
  130.         'width="32" height="32" alt="pear" />This button submits')
  131. );
  132. $fsSubmit->addElement(
  133.     'image''testImage'array('src' => 'http://pear.php.net/gifs/pear-icon.gif')
  134. );
  135.  
  136. // outputting form values
  137. if ('POST' == $_SERVER['REQUEST_METHOD']{
  138.     echo "<pre>\n";
  139.     var_dump($form->getValue());
  140.     echo "</pre>\n<hr />";
  141.     // let's freeze the form and remove the reset button
  142.     $fsButton->removeChild($testReset);
  143.     $form->toggleFrozen(true);
  144. }
  145.  
  146. echo $form;
  147. ?>
  148.   </body>
  149. </html>

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