Custom rule not getting validated
| From: | Ken Restivo | Date: | Sun, 09 Oct 2005 06:57:06 +0000 |
| Subject: | Custom rule not getting validated | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-21291@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have a custom QF rule:
require_once('HTML/QuickForm/Rule/Required.php');
class CustomRequired extends HTML_QuickForm_Rule_Required
{
/**
* Checks if an element is empty
*
* @param string $value Value to check
* @param mixed $options Not used yet
* @access public
* @return boolean true if value is not empty
*/
function validate($value, $options = null)
{
PEAR::raiseError('why isnt this getting callled??!', 111);
if($value == '' || (is_numeric($value) && $value < 1)){
user_error("HEY [$value] is EMPTY", E_USER_NOTICE);
return false;
}
user_error("HEY [$value] is NOT EMPTY", E_USER_NOTICE);
return true;
} // end func validate
function getValidationScript($options = null)
{
return array('', "{jsVar} == '' || {jsVar} < 1");
} // end func getValidationScript
} // end class CustomRequired
$this->form->registerRule('customrequired', NULL,
'CustomRequired',
'lib/customrequired.php');
if(!$this->form->isRuleRegistered('customrequired')){
PEAR::raiseError('customrequired rule did not register',
666);
}
at validation time, $this->form->getRegisteredRules() and, sho' nuff, print_r sez
it's in there:
Array
(
[0] => required
[1] => maxlength
[2] => minlength
[3] => rangelength
[4] => email
[5] => regex
[6] => lettersonly
[7] => alphanumeric
[8] => numeric
[9] => nopunctuation
[10] => nonzero
[11] => callback
[12] => compare
[13] => customrequired
)
And, I've correctly addRule'ed it, and print_r confirms that i did:
Array
(
[job_descriptions-long_description] => Array
(
[0] => Array
(
[type] => customrequired
[format] =>
[message] => Job Description mustn't be empty.
[validation] => server
[reset] =>
[dependent] =>
)
)
[job_descriptions-summary] => Array
(
[0] => Array
(
[type] => customrequired
[format] =>
[message] => Name of Position mustn't be empty.
[validation] => server
[reset] =>
[dependent] =>
)
)
)
And yet..... guess what? I call validate() on this form, this very same form with a valid rule
present and all the above stuff in its QF object vars, and the validate() method on it is never
called. I know that because of the big honking raiseError() I stuck in there. The form validates,
even with empty fields. That method is *not* ever being called. For *text* fields.
On selectboxes, my customrequired::validate() method *is* getting called. So, I know the thing
works, my paths are correct, etc. Why would it refuse to work only on text fields?
Other validations (a date regexp rule, a form rule) *are* being called on this same form. But not
customrequired, on these text fields.
Why? Where would I even look to find out why?
- -ken
- --
- ---------------
The world's most affordable web hosting.
http://www.nearlyfreespeech.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDSL9Ce8HF+6xeOIcRAuV8AJ9mb65nrbbLbQNPRKuvKSCE43e56gCgtlaX
pdfVo6kXZAoF+X78NEJPbRw=
=IuyC
-----END PGP SIGNATURE-----