Re: Custom rule not getting validated-- STILL BROKEN
| From: | Ken Restivo | Date: | Sun, 09 Oct 2005 19:43:02 +0000 |
| Subject: | Re: Custom rule not getting validated-- STILL BROKEN | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21294@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Nevermind again.
That didn't fix it. It's still broken. Dammit.
- -ken
- ------
On Sun, Oct 09, 2005 at 12:40:20PM -0700, Ken Restivo wrote:
> Nevermind, I fixed it. It was pilot error, but I'm still confused as to why it still
> worked, even though I was doing it wrong.
>
> In QF::addRule, I am putting the "name" of the rule (as it was registered) not the
> CLASSNAME as the docs indicate I should.
>
> What puzzles me is why this nonetheless worked for *some* fields, and not for others.
>
> In any case putting "CustomRequired" instead of "customrequired" fixed it.
>
> I'm noting this here so that people can Google for it if they ever find themselves in the
> same situation, which is very easy to do. AddRule's "flexibility" and overloading of
> meanings of its arguments is a bit confusing.
>
> -ken
> ----------
> On Sat, Oct 08, 2005 at 11:57:06PM -0700, Ken Restivo wrote:
> > 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
> >
> > --
> > PEAR General Mailing List (http://pear.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> ---------------
> The world's most affordable web hosting.
> http://www.nearlyfreespeech.net
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
- --
- ---------------
The world's most affordable web hosting.
http://www.nearlyfreespeech.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDSXLGe8HF+6xeOIcRAq+KAKCsbhtTf7a/x1LKbFvXYWB0FRO4kwCgpGnh
RjGsSbaEukh29hrHSK90oxI=
=nrwR
-----END PGP SIGNATURE-----