cvs: pear /HTML_QuickForm/docs QuickForm_example.php
| From: | Bertrand Mansion | Date: | Thu, 16 May 2002 12:35:59 +0000 |
| Subject: | cvs: pear /HTML_QuickForm/docs QuickForm_example.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3860@lists.php.net to get a copy of this message | ||
mansion Thu May 16 08:35:59 2002 EDT
Modified files:
/pear/HTML_QuickForm/docs QuickForm_example.php
Log:
Added validation on client (javascript).
Index: pear/HTML_QuickForm/docs/QuickForm_example.php
diff -u pear/HTML_QuickForm/docs/QuickForm_example.php:1.6
pear/HTML_QuickForm/docs/QuickForm_example.php:1.7
--- pear/HTML_QuickForm/docs/QuickForm_example.php:1.6 Thu Apr 18 10:11:36 2002
+++ pear/HTML_QuickForm/docs/QuickForm_example.php Thu May 16 08:35:58 2002
@@ -6,11 +6,8 @@
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version 2.0
*/
-
require_once ("HTML/QuickForm.php");
-
$form = new HTML_QuickForm('frmTest', 'GET');
-
// Fills with some defaults values
$defaultValues['itxtTest'] = 'Test Text Box';
$defaultValues['itxaTest'] = 'Hello World';
@@ -23,10 +20,8 @@
$defaultValues['ichkABC'] = array('A'=>true,'B'=>true);
$defaultValues['QFText'] = '153.5';
$form->setDefaults($defaultValues);
-
// Elements will be displayed in the order they are declared
$form->addHeader('Normal Elements');
-
// Classic form elements
$form->addElement('hidden', 'ihidTest', 'hiddenField');
$form->addElement('text', 'itxtTest', 'Test Text:');
@@ -44,16 +39,13 @@
$select = &$form->getElement('iselTest');
$select->setSize(5);
$select->setMultiple(true);
-
$form->addHeader('Grouped Elements');
-
// Grouped elements
$name['last'] = &HTML_QuickForm::createElement('text', 'last');
$name['last']->setSize(30);
$name['first'] = &HTML_QuickForm::createElement('text', 'first');
$name['first']->setSize(20);
$form->addElementGroup($name, 'Name (last, first):', 'name',
', ');
-
// Creates a group of text inputs
$areaCode = &HTML_QuickForm::createElement('text', '');
$areaCode->setSize(3);
@@ -65,45 +57,42 @@
$phoneNo2->setSize(4);
$phoneNo2->setMaxLength(4);
$form->addElementGroup(array($areaCode, $phoneNo1, $phoneNo2), 'Telephone:',
'phoneNo', '-');
-
// Creates a radio buttons group
$radio[] = &HTML_QuickForm::createElement('radio', null, null, 'Yes',
'Y');
$radio[] = &HTML_QuickForm::createElement('radio', null, null, 'No',
'N');
$form->addElementGroup($radio, 'Yes/No:', 'iradYesNo');
-
// Creates a checkboxes group
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'A', null,
'A');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'B', null,
'B');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'C', null,
'C');
$form->addElementGroup($checkbox, 'ABC:', 'ichkABC',
'<br>');
-
// Creates a group of buttons to be displayed at the bottom of the form
$buttons[] = &HTML_QuickForm::createElement('submit', null, 'Submit');
$buttons[] = &HTML_QuickForm::createElement('reset', null, 'Reset');
$buttons[] = &HTML_QuickForm::createElement('image', 'iimgTest',
'/images/apache_pb.gif');
$buttons[] = &HTML_QuickForm::createElement('button', 'ibutTest',
'Test Button');
$form->addElementGroup($buttons);
-
$form->addHeader('Using the form element classes directly');
-
$text = new HTML_QuickForm_text('QFText', 'QuickForm Text:');
$form->addElement($text);
-
// applies new filters to the element values
$form->applyFilter('__ALL__', 'trim');
$form->applyFilter('QFText', 'doubleval');
-
// 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', '8,10');
-$form->addRule('QFText', 'Value must be numeric', 'numeric');
-// NEW UPLOADED FILE RULES
+$form->addRule('QFText', 'Value must be numeric', 'numeric',
'', 'client');
+
+// FILE RULES
+/*
$form->addRule('ifilTest', 'Cannot exceed 1776 bytes',
'maxfilesize', 1776);
$form->addRule('ifilTest', 'Must be XML', 'mimetype',
'text/xml');
$form->addRule('ifilTest', 'Must be *.xml', 'filename',
'/^.*\.xml$/');
$form->addRule('ifilTest', 'Required File Upload',
'uploadedfile');
+*/
+
// Tries to validate the form
if ($form->validate()) {
@@ -112,10 +101,9 @@
$form->process();
echo "\n<HR>\n";
}
-
$form->display();
/*echo '<pre>';
print_r($form->toArray());
echo '</pre>';
*/
-?>
+?>
\ No newline at end of file