Re: HTML_QuickForm2: making and_() chained rules non-short-circuited
| From: | Alexey Borzov | Date: | Tue, 05 Jul 2011 13:38:57 +0000 |
| Subject: | Re: HTML_QuickForm2: making and_() chained rules non-short-circuited | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-31161@lists.php.net to get a copy of this message | ||
Hi Christian,
On 05.07.2011 10:22, Christian Weiske wrote:
When chaining rules (i.e. if email address does not match a certain schema, then forename and surname has to be not empty), only the first error is reported because of:If you write your checks as PHP code, they will look something like this: if (!preg_match('/@foobar.com/', $email)) {Evaluation is short-circuited. If first argument of and_() evaluates to FALSE then FALSE is returned without evaluating second argument, if first argument of or_() evaluates to TRUE then TRUE is returned without evaluating second argument.Is there a way to circumvent that short-circuity? The semi code of my form is: $email->addRule('notregex', 'error', '/@foobar.com$/')->or_($firstname->createRule('notempty', 'error')) ->and_($lastname->createRule('notempty', 'error'));When the user enters an email address test@example.org and does not provide firstname nor lastname, only the firstname error is shown. The user fills it (and still missed the last name), and then the last name error is shown. I'd like to show both errors at once. How do I do that?
// set error for $email} else {
if (empty($firstname)) {
// set error for $firstname
}
if (empty($lastname)) {
// set error for $lastname
}
}
As you can see, there is no chain here, there are two separate checks. Thus you should use several addRule() calls rather than try to squeeze everything into one.