SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

Form data validation

As 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

Now in this post back operation we will be assuming that 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.

Here is a demo.

Name
SexMale |Female |
Languages you knowPHP ASP   JavaScript
Select one day
Try Again



Download the full script of form validation


Discuss this tutorial at forum


Further readings
All form components validation with post back and data locking
Checkbox
How to retain form data if validation fails?
How to retain data of a text box after submitting
Retaining status of a check box
Updating checkbox value from & to a table record.
Retaining selected data of a period button of a form
Retaining selected data of a drop down list box of a form
Validating Date: Checking if date exist
Email address validation in a form
PHP Form Validation
is_numeric to check numeric numbers
ctype_alnum to check alphanumeric characters data
ctype_alpha to check alphabetic characters data
How to take care of form & query string variables if Register global is OFF?














 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.