PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
html_QuickForm: pass paramaters to callback rule

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database
View previous topic :: View next topic  
Author Message
pixelterra



Joined: 29 Feb 2008
Posts: 9

PostPosted: Wed Jun 11, 2008 9:40 am    Post subject: html_QuickForm: pass paramaters to callback rule Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Wed Jun 11, 2008 2:47 pm    Post subject: Re: html_QuickForm: pass paramaters to callback rule Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software