Greetings. I have been trying to learn the proper way to validate a webform using best practices and methods. I’ve learned that to do this properly, both server-side and client side must be used to ensure proper data submission and for security issues.
The benefits the user gains by a designer using client-side validation seem to fly right out the window if server-side validation is used also. It seems to defeat the whole purpose of client-side validation? :mad:
In case some of you are confused as to my problem, here is an example.
User inputs data, and submits.
If errors are found, an error div or multiple prompts direct the user to correct the errors on the same page near the form, otherwise the data is submitted, and success div is displayed.
Correct data is submitted to php file (if validation exists, how do I handle the errors, and in a manner that doesn’t make the client-side error correction pointless) and sent to the website owner’s email.
I seriously need help, and any suggestions or tutorials or other information would be greatly appreciated. Please remember though I’m a programming noob, and very right-brained.
otherwise the data is submitted, and success div is displayed.
I guess the data is submitted using AJAX?
If so, don’t just display the success div, but have the PHP script return the result and use that to decide what to display (a success div, an error, whatever).
Thanks for the reply, however I already knew this. What I want to know is what do you do with the errors that might be generated when using server-side validation. Normally when using a simple echo, the PHP spits out black text on a white background, or when using nothing, you simply get a blank page?
Is there a way to validate without the user knowing they’ve submitted errors, especially since they have already dealt with error correction during the client-side validation?
submitting bogus data using either GET or POST directly to the page processing the form data without using the input form at all.
You cannot stop users from doing 1 and/or 2 above.
So in summary, if data integrity/security is an issue (whether user inputs are going into a database or not) thenyou must do server side validation and client side validation is used solely to optionally provide instant feedback to users.
It’s a gigantic pain, if and when the people at Microsoft pull their heads out of their ***** and make Internet Explorer HTML5 compliant as far as the built in validation support, we will all be better off. Internet Explorer is constantly holding back web design and development.
I will take a look at Wufoo, but I really like being self-sufficient which is why I’m trying to learn this stuff.
Because you have a 1 page site, and don’t want to show separate pages for errors and succes, you have two options:
send the form to the same page and add the php code that validates the form data, sends the mail (if no errors are found) and displays the entire page again with succes message or error messages at the right places.
use AJAX: send the form data to a php script using ajax, and then act upon the result sent back by the php script. The easiest way would be (IMO) to have the php script return the entire form including succes message or error messages and change the innerHTML of the form element that contains the form.