Source for file elements.php
Documentation is available at elements.php
* Example of usage for PEAR class HTML_QuickForm
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @author Alexey Borzov <avb@php.net>
* $Id: elements.php,v 1.2 2004/03/22 10:05:09 mansion Exp $
require_once 'HTML/QuickForm.php';
// Use a two-label template for the elements that require some comments
<!-- BEGIN required --><span style="color: #F00;">*</span><!-- END required --><b>{label}</b>
<!-- BEGIN error --><span style="color: #F00;">{error}</span><br /><!-- END error -->{element}
<!-- BEGIN label_2 --><br /><span style="font-size: 80%;">{label_2}</span><!-- END label_2 -->
$renderer = & $form->defaultRenderer ();
$renderer->setElementTemplate ($twoLabel, 'iadvChk');
$renderer->setElementTemplate ($twoLabel, 'iautoComp');
// Fills with some defaults values
$form->setDefaults (array (
'itxtTest' => 'Test Text Box',
'itxaTest' => 'Hello World',
'iselTest' => array ('B', 'C'),
'name' => array ('first'=> 'Adam', 'last'=> 'Daniel'),
'phoneNo' => array ('513', '123', '3456'),
'ichkABC' => array ('A'=>true ,'B'=>true ),
'dateTest1' => array ('d'=>11 , 'm'=>1 , 'Y'=>2003 )
$form->setConstants (array (
// Elements will be displayed in the order they are declared
$form->addElement ('header', '', 'Normal Elements');
$form->addElement ('hidden', 'ihidTest', 'hiddenField');
$form->addElement ('text', 'itxtTest', 'Test Text:');
$form->addElement ('textarea', 'itxaTest', 'Test TextArea:', array ('rows' => 3 , 'cols' => 20 ));
$form->addElement ('password', 'ipwdTest', 'Test Password:');
$form->addElement ('checkbox', 'ichkTest', 'Test CheckBox:', 'Check the box');
$form->addElement ('radio', 'iradTest', 'Test Radio Buttons:', 'Check the radio button #1', 1 );
$form->addElement ('radio', 'iradTest', '(Not a group)', 'Check the radio button #2', 2 );
$form->addElement ('button', 'ibtnTest', 'Test Button', array ('onclick' => "alert('This is a test');"));
$form->addElement ('reset', 'iresTest', 'Test Reset');
$form->addElement ('submit', 'isubTest', 'Test Submit');
$form->addElement ('image', 'iimgTest', 'http://pear.php.net/gifs/pear-icon.gif');
$select = & $form->addElement ('select', 'iselTest', 'Test Select:', array ('A'=> 'A', 'B'=> 'B','C'=> 'C','D'=> 'D'));
$select->setMultiple (true );
$form->addElement ('header', '', 'Custom Elements');
$form->addElement ('date', 'dateTest1', 'Date1:', array ('format'=> 'dmY', 'minYear'=>2010 , 'maxYear'=>2001 ));
$form->addElement ('date', 'dateTest2', 'Date2:', array ('format'=> 'd-F-Y H:i', 'language'=> 'de', 'optionIncrement' => array ('i' => 5 )));
$form->addElement ('date', 'dateTest3', 'Today is:', array ('format'=> 'l d M Y'));
$secondary[0 ][0 ] = "Belle & Sebastian";
$secondary[0 ][1 ] = "Elliot Smith";
$secondary[0 ][2 ] = "Beck";
$secondary[1 ][3 ] = "Noir Desir";
$secondary[1 ][4 ] = "Violent Femmes";
$secondary[2 ][5 ] = "Wagner";
$secondary[2 ][6 ] = "Mozart";
$secondary[2 ][7 ] = "Beethoven";
$hs = & $form->addElement ('hierselect', 'ihsTest', 'Hierarchical select:', array ('style' => 'width: 20em;'), '<br />');
$form->addElement ('advcheckbox', 'iadvChk', array ('Advanced checkbox:', 'Unlike standard checkbox, this element <b>has</b> a value<br />when it is not checked.'), 'Check the box', null , array ('off', 'on'));
$form->addElement ('autocomplete', 'iautoComp', array ('Your favourite fruit:', 'This is autocomplete element.<br />Start typing and see how it suggests possible completions.'), array ('Pear', 'Orange', 'Apple'), array ('size' => 30 ));
$form->addElement ('header', '', 'Grouped Elements');
$form->addGroup ($name, 'name', 'Name (last, first):', ', ');
// Creates a group of text inputs
$form->addGroup (array ($areaCode, $phoneNo1, $phoneNo2), 'phoneNo', 'Telephone:', '-');
// Creates a radio buttons group
$form->addGroup ($radio, 'iradYesNo', 'Yes/No:');
// Creates a checkboxes group
$form->addGroup ($checkbox, 'ichkABC', 'ABC:', '<br />');
// Creates a group of buttons to be displayed at the bottom of the form
$form->addGroup ($buttons, null , null , ' ', false );
// applies new filters to the element values
$form->applyFilter ('__ALL__', 'trim');
// Adds some validation rules
$form->addRule ('itxtTest', 'Test Text is a required field', 'required');
$form->addRule ('itxaTest', 'Test TextArea is a required field', 'required');
$form->addRule ('itxaTest', 'Test TextArea must be at least 5 characters', 'minlength', 5 );
$form->addRule ('ipwdTest', 'Password must be between 8 to 10 characters', 'rangelength', array (8 , 10 ));
// Tries to validate the form
// Form is validated, then processes the data
$form->process ('myProcess', false );
Documentation generated on Mon, 11 Mar 2019 14:16:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|