QuickForm Validation
| From: | Wade Hovind | Date: | Sat, 12 Apr 2003 01:52:46 +0000 |
| Subject: | QuickForm Validation | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-4810@lists.php.net to get a copy of this message | ||
Hello again. Still having problems and still trying to work them out.
Given the following file the first form displays just fine. The second form
shows the error for the name not being there. From what I can see there
isn't any difference. Please. What am I missing???
It would seem to me that validate() should "short circuit" on it's first
call and it seems to do that on the first form.
ANY insight appreciated.
<?php
require_once ("HTML/QuickForm.php");
$form = new HTML_QuickForm('formOne', 'post');
$form->addHeader('Step 1 - Name & Vehicles');
$defaultValues['txtName'] = 'John Doe';
$defaultValues['txtAddress1'] = '123 Any Street';
$form->setDefaults($defaultValues);
$form->addElement('text', 'txtName',
'Name:','size="60" class="formField"');
$form->addElement('text', 'txtAddress1',
'Address:','size="60"
class="formField"');
$form->addElement('submit', null, 'Next');
$form->addRule('txtName', 'Name is required.', 'required');
$form->addRule('txtAddress1', 'Address is required.', 'required');
$form2 = new HTML_QuickForm('formTwo', 'post');
$form2->addHeader('Step 2 - Operators & Vehicle Use');
$form2->addHeader('Main Operator');
$form2->addElement('text', 'txtOp1Name',
'Name:','size="60"
class="formField"');
$form2->addElement('submit', null, 'Next');
$form2->addRule('txtOp1Name', 'Name is required.', 'required');
if (!isset($_SESSION["step"])) {
$_SESSION["step"] = 1;
}
switch($_SESSION["step"]) {
case 1:
if($form->validate()) {
$_SESSION['step']++;
$form->freeze();
}
$form->display();
break;
case 2:
if($form2->validate()) {
$_SESSION['step']++;
$form2->freeze();
}
$form2->display();
break;
default:
print "I received step <b>'" . $_SESSION['step'] .
"'</b> that
dsp_autoQuote.php does not have a handler for.";
$_SESSION['step']=1;
break;
}
?>