csimmons.net :: CFDemo : Form Validation
Garbage Out. Data In.
Validation is an essential part of creating robust, dependable web systems. Failure to account for potential input discrepancies can cause system errors, frustrate users, and worst of all compromise data.
Validation is more than just checking to see if a form field is blank. Proper validation verifies that the user input matches the expected data type in the back end database. Additionally, validation should be carried out at any potential point of failure, which usually means defining client and server side checks.
Good validation also provides understandable feedback to the end users so they have a chance to correct their own errors with minimal aggravation.
Most of the validation examples below utilize JavaScript as the client validation tool. However, Example 4 makes use of Macromedia's Flash Forms (introduced by ColdFusion 7.0).
Here are a few basic validation scenarios for your consideration. Please read the information in the right sidebar before accessing the examples below.
- Example 1: All fields required to have numeric input. To see this example click here and attempt to submit the form with non-numeric characters, or incomplete fields.
- Example 2: Completion of one field creates requirement in other fields. We refer to this as "Conditional Requirement." To see this example click here. Then, attempt to submit the form after selecting "Yes" in the "Use Date Range Field" and failing to supply a date range.
- Example 3: Client + Server Strategy. The user may be able to avoid crucial JavaScript validation at the client level by turning off JavaScript, but a second validation run Server Side can catch it. Go to either of the above examples and turn off JavaScript in your browser using the appropriate method below. Then, try to submit the form.
IE: Tools->Internet Options->Security Tab->Custom Level->Disable Active Scripting
Firefox: Tools->Options->Web Features->Uncheck Enable JavaScript
You may need to refresh (F5) your browser after enabling or disabling JavaScript. - Example 4: See how validation is handled using Macromedia's Flash Forms.
