HTML_QuickForm methods as rules
| From: | Michael Raidel | Date: | Sat, 04 Jan 2003 18:43:17 +0000 |
| Subject: | HTML_QuickForm methods as rules | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-3185@lists.php.net to get a copy of this message | ||
Hello,
I am just trying out HTML_QuickForm and have a little problem: it seems to me, that it's only possible to "registerrule" a function thats not in a class because HTML_QuickForm doesn't know anything about the Class-Object. The registerrule-function has an parameter calles $data2 which is described as "Object parent of above function". Either I make something wrong, or QuickForm doesn't use this parameter at all. I now inserted the following line in the function "validate", directly below the "case 'function':
if ($ruleData[2]) { $function_object =& $ruleData[2]; } else { $function_object =& $this; }
now I use $function_object instead of $this for the "method_exists" and for the if-clause which tests the success of the rule: "if (!$function_object->$ruleData[1]($elementName, $element, $format)) {"
Now all the internal functions continue to work fine, but it's also possible to include a method in the calling script with a line like this:
$this->form->registerRule('compare', 'function', 'cmpPass', $this);
I'm looking forward to hear what you think about this small change.
Michael
P.S.: Would be nice to be able to include additional arguments as an array with each addRule-call. The problem is, that there are a lot of other arguments in the addRule-function already. An additional argument would make it necessary to put all arguments in the call. Maybe someone has a better idea...
P.P.S.:
Has anyone an idea why $function_object =& ($ruleData[2]) ? $ruleData[2] : $this; doesn't work with =&, only with =? No references possible with the ternary operator? Not so important, was just wondering about this ;-)