Quickform validation question
| From: | Dick Visser | Date: | Fri, 22 Dec 2006 09:17:19 +0000 |
| Subject: | Quickform validation question | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26174@lists.php.net to get a copy of this message | ||
Hi guys
Is it possible to register a custom Quickform rule that returns an error string instead of true/false?
I have a form with a textarea, the input (multiple lines) is send to a function. If there are errors, the function true or false. This works good with QuickForm.
I would like the form to provide specific feedback on the input ("Entry on line 3 has syntax errors"). So I have changed my function to provide this feedback.
But QuickForm rules can only understand true/false validation.
I have worked around it by calling the function a second time with an extra parameters, so that it gives back the errors:
(code abbreviated for clarity)
$form->addElement('textarea', 'subs','subscribers, one per line');
$form->registerRule('myFunc','callback','checkMultipleEmail');
// validate by callback func, this time it will return true/false
$form->addRule('subs', 'Errors in subscribers field','myFunc');
if ($form->isSubmitted()) {
if($form->validate()) {
// do stuff
mail('listmaster@terena.org', 'New mj list requested', $body);
header('Location: /thankyou.php');
exit;
} else {
// form errors, call func 2nd time and spit out actual errors from func
$form->setElementError('subscribers',myFunc($form->getSubmitValue('subs'),1,1));
}
}
I wonder if it would be possible to call the function only once i
--
Dick Visser
TERENA IT Support Officer
TERENA Secretariat
Singel 468 D, 1017 AW Amsterdam
The Netherlands
T +31 20 530 44 88 F +31 20 530 44 99
visser@terena.org | www.terena.org