Form data validationAs you have seen we have studied how the post back values inside a form of a text box, radio button, checkbox and drop down selection box is handled. Now we will try to combine this entire components and keep them inside one form. Then we will develop a script which will handle the data once the form is submitted and do a check ( or validation ) for all the components. If the validation is passed then it sends the visitor to a thank you page saying thanks to the visitor for the data, if the validation fails then it will post back the data to the form page with error messages. Here the post back data will be used to fill the components which the user previously filled with data so the visitor will only modify the error part. We will call it data locking
register global is OFF so we will be taking special care to collect data at different pages.
We will also be using header redirection for sending back the visitor to thank you page ( after successful validation ) or back to from with error message once the validation fails.
There are three pages in the script. The form.php page displays the form. This page also receives all the post back data and create the default values of the components. We need not discuss here again how that is done, you can read all the individual form component validations here, with link to different section.
form-check.php checks the form input and does the validation. If the validation passes then it redirect to form-thank.php otherwise it sends back to form.php page with the post back data.
form-thanks.php only display the thank you message.
Download the full script of form validation
Be the first to post comment on this article :