Form Validation validating blank values with min_length and valid_email rules |
Hello, Paul. Thanks for reply.
(10-17-2017, 01:29 PM)PaulD Wrote: If a field is required, then you have to fill it in. If it is not, you do not have to. Ok. Only the required fields have the 'required' rule. (10-17-2017, 01:29 PM)PaulD Wrote: If you have an email field, that is not required, and the user does not fill it in, then it should not fail the validation, even if the validation says min_length 50, valid email, or whatever. It is not required, so no input is a pass. Here are the "fail". If the user do not send a field that is not required, then this field is not validated (of course, and it is happening in the current Form Validation). But, if the user send a field with blank value the validation pass. Look, the field is set with '', a blank string. And the validation accept it as a valid email, min lenght, or whatever. This is a fail. A blank string is not a valid email! (10-17-2017, 01:29 PM)PaulD Wrote: With your city field example above, if I had a user presented with 12 possible fields that could be updated, you would prefill this with the existing data, and if he saved the form, all the possible fields that could have been updated, are updated. You might test to see if the field had changed but why bother, just update all 12. No. It's not possible "prefil" the resquest. I need only the necessary data. If the user send only the email, he could not to empty this value. Because the API need a Valid Email. If he want to update the email he need to send a valid email. Blank values are not accepted in the email and because of this, in the insert action (registration) the email was required. But on the update it is not required. But, if sent, he MUST send a valid email, blank string is not a valid email. If blanks values was accepted, then would not be necessary define a validation rule with min_length[1]. It's obvious that a blank string have 0 length and that the validation never could accept this! (10-17-2017, 01:29 PM)PaulD Wrote: I would normally do this by the user selecting exactly what field he wanted to update. Say he chose his email address, then only the email address input is displayed, prefilled, for him to update. If he emptied it and pressed save, the field (assuming it is not required) would be updated to blank or null. Ok. But this is not just for HTML Forms. The validation is for REST. POST, PUT and PATCH methods. (10-17-2017, 01:29 PM)PaulD Wrote: But, if the form validation does not work the way you want it to, you customise it to suit (which might be ill advised) or just do your own validation with a regex and some issets and whatever else you wanted. Yes. A simple way to customize this was adding a check if the input field have blank string or not. Then I added a 'isset' rule and is working fine. --- The fact is that the name of the library is Form Validation and not just Validation. I'm using it out of a form. But what I noted is that blank values are accepted when we have rules requiring something that is not blank. If is said "we need a valid email" and the user send a blank value, it is not a valid email then the Validation MUST say it. If is said "we need min 5 characters " and the user send a blank value, it do not have 5 chars then the Validation MUST say it. If the field is not required the user do not need send it. But if he sent, then the validation MUST works. And this is not occuring at the moment if the user send blank values. That way the client can fool the system and zero all its fields. The rules that are there, will serve no purpose. |
Welcome Guest, Not a member yet? Register Sign In |