Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.2.16

Bug #34 'email' validation rules don't work
Submitted: 2003-09-25 17:11 UTC
From: christian dot ullrich at asqf dot de Assigned:
Status: Bogus Package: HTML_QuickForm
PHP Version: 4.3.3 OS: Linux
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 39 - 22 = ?

 
 [2003-09-25 17:11 UTC] christian dot ullrich at asqf dot de
Description: ------------ Validation rules of type 'email' don't work right. Their regex prohibits empty values, so the fields should, in effect, be required fields in addition to the syntax check. They aren't, however, and the only way to get the rules to work is to add a dummy 'required' rule. Reproduce code: --------------- $form = new HTML_QuickForm("example"); $form->addElement('text', 'emadr', 'E-Mail address'); $form->addRule('emadr', 'Please enter a correct address', 'email'); if ($form->validate()) { die; } $form->display(); Expected result: ---------------- The validation message should be displayed. Actual result: -------------- The validation message isn't displayed, because the field is not known to be required.

Comments

 [2003-09-25 17:15 UTC] mansion at php dot net
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Use: $form->addRule('emadr', 'Email is required', 'required'); $form->addRule('emadr', 'Please enter a correct address', 'email'); Only required elements will be validated, unless they are not empty.
 [2003-09-25 18:23 UTC] christian dot ullrich at asqf dot de
If that's right, then there's not one, but two bugs. One is a documentation bug (this behaviour isn't documented in the PEAR docs), the second is the existence of the rule type 'emailorblank', because this would be accomplished nicely by using 'email' without making it a required field. As for your advice to double-check the docs: There's an awful lot of docs and I think if validate() works like this, it should be documented there or with addRule(). To summarize: There are two different possible sets of semantics for the rule types 'email', 'emailorblank' and 'required'. Either 'email' means that the only valid value is a syntactically correct email address, in which case the field must be required too (and 'emailorblank' is the same, but not a required field), or it means that any actual data entered into the field must be a syntactically correct email address, but if there's nothing there, it's fine, too (in which case 'emailorblank' is completely useless).
 [2003-09-25 18:54 UTC] avb
There is a documentation problem indeed. The doc http://pear.php.net/manual/en/package.html.html-quickform.intro-validation.php states: "The fact that an element is required triggers the use of the other validation rules set for that same element." which is not clear. There are probably some mentions in the changelog, too. 'emailorblank' is an artifact of an old QuickForm version and will be removed. The validation now works (and will continue to work) as follows: if the element is not required, it is considered valid, checks for the other rules are not run. If it is required and present then it is validated against all other rules.
 [2003-09-25 19:50 UTC] mansion at php dot net
'emailorblank' was kept for BC sake and will be removed in the next "major" version. As you can notice, it is not documented in the docs so that developers are not encouraged to use it. If the explanation in the docs about required elements is not clear, we can maybe rephrase it: Elements with empty values won't be validated. Elements with values set will be validated against the rules they have been set. Required elements will always be validated whether they are empty or not. (well, I am not sure it's clearer) It is like there are two levels of validation. First we check if the element is required, then, if it's not empty, we check if it matches the rule. The first error met will stop the validation process for that element, that's why the order you add your rules matter. About the "double-check" text, that's something automatically generated by the bug system, which I don't have control over, so excuse me if it sounded rude :)
 [2005-06-20 12:56 UTC] dev dot mithi at gmail dot com
I have used DB_Table to take input for email. and email is required. But email checking is not giving any error if some character like "'" is entered with email address. Plz let me know how can I fix this problem.