 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
pixelterra
Joined: 29 Feb 2008 Posts: 9
|
Posted: Wed Jun 11, 2008 9:40 am Post subject: html_QuickForm: pass paramaters to callback rule |
|
|
I would like to have a numeric range callback validation rule. But I cannot figure out how to pass the callback function any range parameters. See below for what I am hoping to achieve.
function numeric_range ($val,$range) {
if ($val > $range[0] && $val < $range[1]) {
return true;
} else {
return false;
}
}
$f->addRule('card_exp_month', 'Numeric value between 10 and 25', 'callback', 'numeric_range', array(10,25);
My problem is that the callback func is only passed the $val parameter. I tried to look at the callback.php source to figure out how to send a paramater, but it's pretty dense...
If this can't be done, I'm forced to write custom functions for EVERY range I'll need. This precludes dynamic ranges, obviously : (
The following line from the documentation is enticing however: All other builtin rules will only handle a single element name. callback rules can also handle an array here, but the callback function you provide will obviously need to properly handle an array of values.
It of course leaves how to properly handle an array of values to the reader, naturally. I'm trying hard not to be disappointed by the very sparse user documentation for the pear library. I am new to pear, and had high hopes for it initially. But after 4 months on a project using pear, I'm continually daunted by poor or absent documentation... |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Wed Jun 11, 2008 2:47 pm Post subject: Re: html_QuickForm: pass paramaters to callback rule |
|
|
| pixelterra wrote: | I would like to have a numeric range callback validation rule. But I cannot figure out how to pass the callback function any range parameters. See below for what I am hoping to achieve.
function numeric_range ($val,$range) {
if ($val > $range[0] && $val < $range[1]) {
return true;
} else {
return false;
}
}
$f->addRule('card_exp_month', 'Numeric value between 10 and 25', 'callback', 'numeric_range', array(10,25);
|
Have a look at example 47-1 and it will work as expected:
http://pear.php.net/manual/en/package.html.html-quickform.intro-validation.php
| pixelterra wrote: | | I'm trying hard not to be disappointed by the very sparse user documentation for the pear library. I am new to pear, and had high hopes for it initially. But after 4 months on a project using pear, I'm continually daunted by poor or absent documentation... |
Instead of complaining here, please report bugs (with type "Documentation bug") in the bug tracker on pear.php.net for the package(s) that has/have incomplete documentation. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|