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

Bug #3501 Handling of empty file fields
Submitted: 2005-02-17 11:41 UTC
From: fredericpoeydomenge Assigned: avb
Status: Closed Package: HTML_QuickForm
PHP Version: Irrelevant OS: Debian GNU/Linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-02-17 11:41 UTC] fredericpoeydomenge
Description: ------------ There is a problem in handling of empty file fields : when a "file" element is not declared as "required" in a form, and that no file is submitted, the validate() method from a custom class rule is ALWAYS called, whereas it shouldn't be called. Reproduce code: --------------- require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/Rule.php'; class ImageWeb extends HTML_QuickForm_Rule { function validate($value) { return FALSE; } } $form = & new HTML_QuickForm('builtin'); $form->registerRule('webpic','rule','ImageWeb'); $form->addElement('file', 'picture', 'Picture:'); $form->addRule('picture', 'Invalid Web picture', 'webpic'); $form->addElement('submit'); $form->validate(); $form->display(); Expected result: ---------------- when no file is submitted, and the element is not "required", then the validate() method from the custom class rule must not be called. Actual result: -------------- the validate() method from the custom class rule IS called, thus the form does not validate when no file is submitted

Comments

 [2005-02-17 13:43 UTC] adeliru at hotmail dot com
Hi, I've had a problem with empty field, it might be related so I'll explain it here, forgive me if it is inappropriate (working on WinXP with wamp, just beginning with PEAR): If I try a simple case such as this : " require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm('firstForm'); $form->addElement('header', null, 'QuickForm tutorial example'); $form->addElement('text', 'name', 'Enter your name:', array('size' => 50, 'maxlength' => 255)); $form->addElement('submit', null, 'Send'); //$form->addRule('name', 'Please enter your name', 'required', null, 'client'); if ($form->validate()) { echo '<h1>Hello, ' . htmlspecialchars($form->exportValue('name')) . '!</h1>'; echo "--".$_POST['name']."--"; if (isset($_POST['name'])) {print "ok";} exit; } else{ $form->display(); } " When you have the addRule, everything works fine. But if you have no rule, then the form is validated you get : "Hello, ! ----ok" Is that a normal bahaviour ? validate() does not check for empty fields or considers them not empty ? Which migth be latter because the isset for $_POST returns true. But " if ($_POST['name']) {print "ok";} " would give : "Hello, ! ----" And in some case I've seen the validate return a " " value ! I'm completly at a loss with the behaviour of validate(). The result is that if I send a form without any data it is always validated. From all the tutorials I've read I understood it should do the contrary.
 [2005-06-18 20:59 UTC] avb
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.