Is there a good technique to ensure that the validation performed by PHP is identical to that performed my Javascript?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There used to be a time where we would validate using javascript only and then people saw that you could bypass javascript validation so they started validating with PHP/ASP too. And then, people got bored, but sudenly, AJAX apperead 🙂
My recommendation that i use about 50% of the time is the following:
Just POST your form via ajax using your library of choice (i use jQuery) to a validation script made in php, expect a JSON return giving your errors or return some HTML to display to your user with the error. Using this technique, it looks like javascript validation because the page doesn’t change and the validation is done on PHP side only.
Thats what i tend to implement when i can unless i’m forced to use file uploads (You can’t use file uploads correctly with ajax posting) or unless my boss wants me to absolutely do real Javascript validation.