Home » HTML » HTML_QuickForm » Bug #6979
registerRule('callback') should support methods
Details
| Request #6979 | registerRule('callback') should support methods |
|---|---|
| Submitted | 2006-03-01 17:24 UTC |
| From | vl dot homutov at gmail dot com |
| Status | Bogus |
| Package | HTML_QuickForm |
| PHP Version | Irrelevant |
| OS | Gentoo |
| Roadmaps | (Not assigned) |
Comments
[2006-03-01 17:24 UTC] vl dot homutov at gmail dot com
Description:
------------
HTML_QuickForm::registerRule() has ability to register callback function to validate form contents.
To do so, we need to specify function name. But this is not enough, when we want to register a method of class as a callback function.
registerRule is unable to process standart php way of passing such things as array('classname or object','funcname').
in Callback.php, line 70 we see:
return $callback[0]($value, $options);
which means that this code is unable to use methods as callback function.
Decision is simple: change this to:
call_user_func($callback[0],$value,$options);
works fine and is very usefull.
Test script:
---------------
example of usage:
i have a class, which deals with users in database.
class is DB_DataObject based.
To validate a form against database, it is very usefull
to have ability to register validation function, which
cheks if user with submitted name already exists in database:
if it does, form will produce an error.
$form->registerRule('login_exists','callback',array($this,'user_safe_to_add'));