Source for file basic-elements.php
Documentation is available at basic-elements.php
* Usage example for HTML_QuickForm2 package: basic elements
* $Id: basic-elements.php,v 1.2 2007/04/17 14:00:40 mansion Exp $
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
/* styles borrowed from an older release of Tableless Renderer for QF.
Newer styles work worse with nested fieldsets */
font-family: Arial,sans-serif;
form input, form textarea, form select {
form span.error, form span.required {
<title>HTML_QuickForm2 basic elements example</title>
'a' => 'Letter A', 'b' => 'Letter B', 'c' => 'Letter C',
'd' => 'Letter D', 'e' => 'Letter E', 'f' => 'Letter F'
if ('fieldset' == $element->getType ()) {
} elseif ('hidden' == $element->getType ()) {
echo '<div style="display: none;">' . $element->__toString () . "</div>\n";
echo '<div class="qfrow"><label class="qflabel" for="' . $element->getId () .
'">' . $element->getLabel () . '</label> <div class="qfelement">' .
$element->__toString () . "</div></div><br />\n";
echo '<fieldset' . $fieldset->getAttributes (true ) . ">\n<legend>" .
$fieldset->getLabel () . "</legend>\n";
foreach ($fieldset as $element) {
require_once 'HTML/QuickForm2.php';
// data source with default values:
'textTest' => 'Some text',
'areaTest' => "Some text\non multiple lines",
'selMultipleTest' => array ('b', 'c'),
$fsText = $form->addElement (
'fieldset', null , null , 'Text boxes'
'text', 'textTest', null , 'Test Text:', array ('style' => 'width: 300px;')
'password', 'pwdTest', null , 'Test Password:', array ('style' => 'width: 300px;')
$area = $fsText->addElement (
'textarea', 'areaTest', null , 'Test Textarea:',
array ('style' => 'width: 300px;', 'cols' => 50 , 'rows' => 7 )
$fsNested = $form->addElement (
'fieldset', null , null , 'Nested fieldset'
'text', 'userTest', null , 'Username:', array ('style' => 'width: 200px')
'password', 'passTest', null , 'Password:', array ('style' => 'width: 200px')
// Now we move the fieldset into another fieldset!
$fsText->insertBefore ($fsNested, $area);
$fsSelect = $form->addElement (
'fieldset', null , null , 'Selects'
'select', 'selSingleTest', array ('options' => $options), 'Single select:'
'select', 'selMultipleTest', array ('options' => $options), 'Multiple select:',
array ('multiple' => 'multiple', 'size' => 4 )
$fsCheck = $form->addElement (
'fieldset', null , null , 'Checkboxes and radios'
'checkbox', 'boxTest', array ('content' => 'check me'), 'Test Checkbox:'
'radio', 'radioTest', array ('content' => 'select radio #1'), 'Test radio:', array ('value' => 1 )
'radio', 'radioTest', array ('content' => 'select radio #2'), '(continued)', array ('value' => 2 )
$fsButton = $form->addElement (
'fieldset', null , null , 'Buttons'
$testReset = $fsButton->addElement (
'reset', 'testReset', null , null , array ('value' => 'This is a reset button')
'inputbutton', 'testInputButton', null , null ,
array ('value' => 'Click this button', 'onclick' => "alert('This is a test.');")
'button', 'testButton', array ('content' => '<img src="http://pear.php.net/gifs/pear-icon.gif" '.
'width="32" height="32" alt="pear" />This button does almost nothing'),
null , array ('onclick' => "alert('Almost nothing');", 'type' => 'button')
// submit buttons in nested fieldset
$fsSubmit = $fsButton->addElement (
'fieldset', null , null , 'These buttons can submit the form'
'submit', 'testSubmit', null , null , array ('value' => 'Test Submit')
'button', 'testSubmitButton', array ('content' => '<img src="http://pear.php.net/gifs/pear-icon.gif" '.
'width="32" height="32" alt="pear" />This button submits'),
null , array ('type' => 'submit')
'image', 'testImage', null , null , array ('src' => 'http://pear.php.net/gifs/pear-icon.gif')
// outputting form values
if ('POST' == $_SERVER['REQUEST_METHOD']) {
// let's freeze the form and remove the reset button
$fsButton->removeChild ($testReset);
$form->toggleFrozen (true );
echo '<form' . $form->getAttributes (true ) . ">\n";
foreach ($form as $element) {
Documentation generated on Mon, 11 Mar 2019 15:00:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|