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

Bug #243 Syntax Error in Global Validation Rules
Submitted: 2003-11-14 09:36 UTC
From: imho at auspantheon dot com Assigned:
Status: Bogus Package: HTML_QuickForm
PHP Version: Irrelevant OS: n/a
Roadmaps: (Not assigned)    
Subscription  


 [2003-11-14 09:36 UTC] imho at auspantheon dot com
Description: ------------ On line 1290, the line: $this->_errors += $res; I believe it should be: =+ Resulting Error: Fatal error: Unsupported operand types in /usr/share/pear/HTML/QuickForm.php on line 1290 Reproduce code: --------------- This error can be reproduced by submitting to the page where the form was constructed,using a form which doesn't contain a required element.

Comments

 [2003-11-14 09:44 UTC] imho at auspantheon dot com
I don't know why =+ fixes the problem, but it does cause problems in normal QuickForm use. I do not know the solution, I'll leave that to the developers. As for the expected behaviour, I would expect the QuickForm to trigger the 'required' rule and display appropriatly. Thanks for your time.
 [2003-11-14 12:39 UTC] avb
The error can only appear if you add the global rule via addFormRule() and return some wrong value from it. Consider fixing your custom function (the source of which you didn't show, BTW) instead of proposing obviously broken "fixes" for the package.
 [2003-11-15 00:35 UTC] imho at auspantheon dot com
<? function _is_student($fields) { if (!isset($fields['student'])) return false; if (in_array($fields['student'], $this->_students)) return true; return array('student' => 'No such student found.'); } ?> Above is my custom function, a var_dump of $res ($this->_errors += $res;) shows that when $res is false (as returned by my function when $fields['student'] does not exist) will crash the script. I'm sorry if you feel I'm wasting your time, however your rudeness is not appreciated. As for an "obviously broken" fix, The line (if ($res === false) continue;) added into the loop above ($this->_errors += $res;) seems to fix the problem, and displays the expected result.
 [2003-11-15 08:39 UTC] avb
Excuse me, but the docs for addFormRule() [1] explicitly say: "The rule function/method should return TRUE in case of successful validation and array('element name' => 'error') when there were errors." Your function returns false, the validate() method is not prepared to handle this and thus breaks. I don't really think that adding a check for whatever junk can also be returned from such a method is the way to go. http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addformrule.php