1. Home
  2. Computing & Technology
  3. Web Design / HTML

Form Validation

Make Sure Your Forms are Filled In

By Jennifer Kyrnin, About.com

Once you have an HTML form up and running, you will often want to make sure that all the important fields are filled in. For example, if you are going to send an email confirmation letter, the email address should be included in the form fields, and it should appear to be valid.

There are, basically, two ways to validate your forms:

  1. Using a CGI script
  2. Using JavaScript

There are benefits and drawbacks to each method.

JavaScript Pros

  • Using JavaScript you don't use any server processor time. All the processing is done on the client computer.
  • It often appears to work faster than the CGI validation.
  • Since the form page has not changed, it is easy for the reader to fix the errors.

JavaScript Cons

  • JavaScript only works on browsers that have it enabled. If the JavaScript is disabled, your error checking doesn't get done.

CGI Pros

  • Using a CGI to validate ensures that every time the form is submitted, the validation will run.

CGI Cons

  • CGI puts more load on the Web server, and every function that is included in the CGI is one more task for the server.
  • CGI can be slow to run.
  • If there is an error, the customer has to either go back to the first page of the form, or the CGI needs another function to rewrite the form page.

The way I handle this is to have the majority of the error checking done with JavaScript. That way, it is fast and easy for the readers. I then recheck the vital elements of the form with the CGI.

Page 2: How to Use JavaScript to Validate HTML Forms

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. HTML and XHTML
  5. XHTML
  6. Forms
  7. HTML Form Validation - Validating Forms with JavaScript or CGI - Pros and Cons of Form Validation Methods

©2008 About.com, a part of The New York Times Company.

All rights reserved.