Re: Re[2]: [PEAR] [QF] - add rule - callback rule usingbuilt-in/registered rule inside
| From: | Bertrand Mansion | Date: | Tue, 27 Jan 2004 13:02:07 +0000 |
| Subject: | Re: Re[2]: [PEAR] [QF] - add rule - callback rule usingbuilt-in/registered rule inside | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10380@lists.php.net to get a copy of this message | ||
<mike.carter@personalmedicaladvisor.co.uk> wrote :
>
>
>> -----Original Message-----
>> From: Bertrand Mansion [mailto:bmansion@mamasam.com]
>>
>> <Sebastian.Baran@dialcom.com.pl> wrote :
>>
>>>
>>>
>>> Tuesday, January 27, 2004, 11:40:20 AM, you wrote:
>>>
>>>>> -----Original Message-----
>>>>> From: Sebastian Baran [mailto:Sebastian.Baran@dialcom.com.pl]
>>>>>
>>>>> I want to create custom callback rule. But part of it's
>> functionality
>>>>> is going to be the same as one of built-in rules. My
>> question is - is
>>>>> it possible to call built-in rule from my callback function? Or
>>>>> do I have to rewrite built-in rule functionality by hand in my
>>>>> function?
>>>
>>> MC> Depending on exactly what your rule is going to do,
>>> MC> could you not add the rules in the right order, so that
>> the built-in one
>>> is
>>> MC> called before your custom callback one?
>>>
>>> MC> - Mike
>>>
>>>
>>> Well, I didn't think about it this way. It's good idea - I'll try to
>>> put two rules instead of one complex rule. This will be
>> sufficient for
>>> most cases.
>>>
>>> But if I would like to have just one rule to overwrite
>> error messages
>>> generated by two rules and display just one error message? For
>>> example:
>>> - one rule - built-in 'email' to initially check if email is ok
>>> - second rule - callback to check something more complex
>> (for example
>>> if email is in DB or something).
>>>
>>> Is it good way to do it? Can I put both rules into one callback rule
>>> calling buil-in rule first?
>>
>> I don't see any reason why you would want to do that ?
>
> If the email address "ok" check (via regex) is done on the client side
> before submitting the data to the server this should be fine. Because the
> second check (to see if its in the dbase) would not happen unless phase 1
> was passed.
>
> However if all validation is server side only - ie regex on the server,
> followed by a DB lookup, then two error messages would be returned - in
> effect telling the user the same thing twice!
>
> - The email address is not valid
> - The email address is not in the database
>
> Doesnt look too great as one infers the other. Computers are supposed to
> be clever ;-)
I don't know about computers but at least QuickForm is clever in that
matter. If email is not valid, then the following validation tests for the
email value stop and only the first error is returned. That's why the order
you set your rules matters.
Bertrand Mansion
Mamasam