PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #6979

registerRule('callback') should support methods

Details

Request #6979registerRule('callback') should support methods
Submitted2006-03-01 17:24 UTC
Fromvl dot homutov at gmail dot com
StatusBogus
PackageHTML_QuickForm
PHP VersionIrrelevant
OSGentoo
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'));