Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.2.16

Bug #7470 $form->Validate() == true after succesful $form->SetElementError() call
Submitted: 2006-04-24 11:02 UTC
From: ben dot lancaster at design-ontap dot co dot uk Assigned: avb
Status: Closed Package: HTML_QuickForm (version 3.2.5)
PHP Version: 4.4.1 OS: FC4
Roadmaps: (Not assigned)    
Subscription  


 [2006-04-24 11:02 UTC] ben dot lancaster at design-ontap dot co dot uk (Ben)
Description: ------------ Validate() still returns true even after SetElementError() has been succesfully applied to an element. Suggest adding an additional flag to the SetElementError() method to indicate whether the error set should force Validate() to fail. Test script: --------------- <?php $form = new HTML_QuickForm; $form->addElement('text','field','This field should fail:'); if($form->isSubmitted()) $form->setElementError('field','Sorry, that field is invalid'); if($form->Validate()) echo 'validated'; else echo 'not validated'; ?> Expected result: ---------------- not validated Actual result: -------------- validated

Comments

 [2006-05-29 14:37 UTC] avb (Alexey Borzov)
Looks like there is an actual bug here. If the form has no validation rules defined then validate() returns true, if there are rules then it returns false even if they pass: <?php require_once 'HTML/QuickForm.php'; $_POST['field'] = 'foo'; $form = new HTML_QuickForm(); $form->addElement('text','field','This field should fail:'); if($form->isSubmitted()) $form->setElementError('field','Sorry, that field is invalid'); echo "\n" . ($form->Validate()? 'validated': 'not validated'); $form->addRule('field', 'The field is required', 'required'); echo "\n" . ($form->Validate()? 'validated': 'not validated'); ?>
 [2006-06-03 11:57 UTC] avb (Alexey Borzov)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.