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

Bug #3042 auto-detection based validation harmful
Submitted: 2004-12-27 20:52 UTC
From: andrew dot clark at ucsb dot edu Assigned: justinpatrin
Status: Closed Package: DB_DataObject_FormBuilder
PHP Version: 4.3.10 OS: FreeBSD 4.10
Roadmaps: (Not assigned)    
Subscription  


 [2004-12-27 20:52 UTC] andrew dot clark at ucsb dot edu
Description: ------------ DO_FormBuilder tries to guess validation rules, but overrides rules added to form (through postGenerateForm, for example). For integer types that are not integers in the form (IP address converted from dotted decimal to long notation, for example), this is harmful. Here's the affected code in FormBuilder.php: // Auto-detect field types depending on field's database type switch (true) { case ($type & DB_DATAOBJECT_INT): if (!isset($element)) { $element =& $this->_createIntegerField($key); } $elValidator = 'numeric';

Comments

 [2004-12-28 02:46 UTC] justinpatrin
Well, a number DB type will only be a number in the DB. Are you using preProcessForm() to change the value? I can see the problem this can cause. We could handle it in one of a few ways. 1) Only set a validator automatically if there is no element in preDefElements. 2) Add a new config array called somehting like elementRuleType which could set the rule for an element. Personally I would rather the first option.
 [2004-12-28 11:56 UTC] mw21st
Another option I can think of: An option called "autoRuleNoApply" or something that you can either set to TRUE to turn off auto-applied rules alltogether, or put in an array with element names for which no auto-rule may be applied.
 [2004-12-28 18:59 UTC] justinpatrin
Something like autoRuleNoApply makes sense to me. And it could be an array or "false" to disable all. I assume array() would count as true? (i.e. we would check for === false)
 [2005-01-02 00:40 UTC] justinpatrin
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. Since there is only one automatic rule in FB right now I've just moved it into that if(). If you set up an element in preDefElements the rule will not be applied.