cvs: pear /HTML_QuickForm/docs QuickForm_example.php

From: Date: Thu, 13 Sep 2001 14:29:51 +0000
Subject: cvs: pear /HTML_QuickForm/docs QuickForm_example.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-840@lists.php.net to get a copy of this message
mansion Thu Sep 13 10:29:51 2001 EDT Modified files: /pear/HTML_QuickForm/docs QuickForm_example.php Log: Some fixes for radio and checkboxes elements. Comments and cosmetic additions. Index: pear/HTML_QuickForm/docs/QuickForm_example.php diff -u pear/HTML_QuickForm/docs/QuickForm_example.php:1.1 pear/HTML_QuickForm/docs/QuickForm_example.php:1.2 --- pear/HTML_QuickForm/docs/QuickForm_example.php:1.1 Thu Sep 6 06:08:16 2001 +++ pear/HTML_QuickForm/docs/QuickForm_example.php Thu Sep 13 10:29:51 2001 @@ -1,47 +1,84 @@ <?php +/** +* Example of usage for PEAR class HTML_QuickForm +* +* @author Adam Daniel <adaniel1@eesus.jnj.com> +* @author Bertrand Mansion <bmansion@mamasam.com> +* @version 1.2 +*/ + require_once ("HTML_QuickForm/QuickForm.php"); $form = new HTML_QuickForm('frmTest'); + +if ($REQUEST_METHOD == "POST") { + // Uses posted values + $form->loadValues(); +} else { + // Fills with some defaults values + $defaultValues["itxtTest"] = "Test Text Box"; + $defaultValues["iradYesNo"] = "Y"; + $defaultValues["ichkABC"] = "A,B"; + $defaultValues["iselTest"] = "C"; + $form->loadDefaults($defaultValues); +} + +// Elements will be displayed in the order they are declared +// Set form caption + $form->addHeader("Test Form"); + +// Classic form elements + $form->addElement('hidden', 'ihidTest', 'hiddenField'); $form->addElement('text', 'itxtTest', '', 'Test Text:'); $form->addElement('textarea', 'itxaTest', '', 'Test TextArea:'); $form->addElement('password', 'ipwdTest', '', 'Test Password:'); $form->addElement('file', 'ifilTest', '', 'File:'); -$form->addElement('select', 'iselTest', array('A'=>'A', 'B'=>'B'), 'Test Select:'); +$form->addElement('select', 'iselTest', array('A'=>'A', 'B'=>'B','C'=>'C','D'=>'D'), 'Test Select:'); + +// Creates a group of text inputs $phone[] = $form->createElement('text', null, null, null, array("size"=>3, "maxlength"=>3)); $phone[] = $form->createElement('text', null, null, null, array("size"=>3, "maxlength"=>3)); $phone[] = $form->createElement('text', null, null, null, array("size"=>4, "maxlength"=>4)); $form->addElementGroup($phone, 'Telephone:', 'phoneNo'); -$radio[] = $form->createElement('radio', '', 'Y', 'Yes'); -$radio[] = $form->createElement('radio', '', 'N', 'No'); +// Creates a radio buttons group + +$radio[] = $form->createElement('radio', 'iradYesNo', 'Y', 'Yes'); +$radio[] = $form->createElement('radio', 'iradYesNo', 'N', 'No'); $form->addElementGroup($radio, 'Yes/No:', 'iradYesNo'); -$checkbox[] = $form->createElement('checkbox', '', 'A', 'A'); -$checkbox[] = $form->createElement('checkbox', '', 'B', 'B'); -$checkbox[] = $form->createElement('checkbox', '', 'C', 'C'); +// Creates a checkboxes group + +$checkbox[] = $form->createElement('checkbox', 'ichkABC', 'A', 'A'); +$checkbox[] = $form->createElement('checkbox', 'ichkABC', 'B', 'B'); +$checkbox[] = $form->createElement('checkbox', 'ichkABC', 'C', 'C'); $form->addElementGroup($checkbox, 'ABC:', 'ichkABC'); +// Creates a group of buttons to be displayed at the bottom of the form + $buttons[] = $form->createElement('submit', '', 'Submit'); $buttons[] = $form->createElement('reset', '', 'Reset'); $buttons[] = $form->createElement('image', 'iimgTest', '/images/apache_pb.gif'); $buttons[] = $form->createElement('button', 'ibutTest', 'Test Button'); $form->addElementGroup($buttons); +// 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', 'client'); $form->addRule('ipwdTest', 'Password must be between 8 to 10 characters', 'rangelength', '8,10', 'client'); +$form->addRule('itxaTest', 'Test TextArea is a required field', 'required'); -$defaultValues = array('itxtTest'=>'Test Text Box', 'iradYesNo'=>'N', 'ichkABC'=>'A,B', 'iselTest'=>'DB'); -$form->loadDefaults($defaultValues); -$form->loadValues(); +// Tries to validate the form if ($form->validate()) { + // Form is validated, then processes the data $form->process(); echo "\n<HR>\n"; } + $form->display(); ?>

« previous php.pear.cvs (#840) next »