Different validation techniques apply to different ColdFusion tags or coding environments; for example, you can use masking only in HTML and Macromedia Flash format cfinput
tags. Validation techniques also vary in where and when they execute; for example, on the client browser when the user submits form data, or on the server when processing data.
The following table describes the ColdFusion MX validation techniques:
Validation technique | Applies to | Where and when performed | Description |
---|---|---|---|
mask ( |
HTML and Flash format |
On the client as the user enters data |
ColdFusion MX generates JavaScript or ActionScript to directly control the data a user enters by specifying a pattern. For example, 999-999-9999 requires a user to enter ten digits, and automatically fills in the dash (-) separators to create a formatted telephone number. For detailed information on using masks, see Handling invalid data. |
onBlur (
|
|
On the client when the data field loses focus |
In HTML and XML format, ColdFusion MX generates JavaScript that runs on the browser to check whether entered data is valid and provide immediate feedback, if the entry is invalid. In Flash format, uses Flash built-in validation routines. |
onSubmit (
|
|
On the client when the user clicks Submit |
In HTML or XML format, the validation logic is identical to onBlur validation, but the test is not done until the user submits the form. In Flash format, this validation type is identical to onBlur Validation. Flash checks do not differentiate between the two events for validation. |
onServer (
|
|
On the server when ColdFusion gets the submitted form |
ColdFusion MX checks submitted data for validity and runs a validation error page if the data is not valid. You can use the |
hidden field |
All Forms, including HTML-only forms |
On the server when ColdFusion gets the submitted form |
ColdFusion MX uses the same validation logic as with onServer validation, but you must create additional, hidden, fields and you can use this technique with HTML tags or CFML tags. For detailed information on using hidden fields, see Validating form data using hidden fields. |
JavaScript ( |
|
On the client, when the user clicks Submit, before field-specific onSubmit validation |
ColdFusion MX includes the specified JavaScript function in the HTML page it sends to the browser, and the browser calls it. For detailed information on using JavaScript for validation, see Validating form input and handling errors with JavaScript. |
|
ColdFusion variables |
On the server, when the function executes |
ColdFusion MX tests the variable to determine whether it follows a specified validation rule and the function returns true or false. For more information on using the |
|
ColdFusion variables |
On the server, when the tag executes |
ColdFusion MX checks the specified variable. If the value does not meet the validation criteria, ColdFusion generates an expression exception. For more information on using the |
|
UDF and CFC function arguments |
On the server, when a function is called or invoked |
ColdFusion MX checks the argument value when it is passed to the function. If the value does not meet the validation criteria, ColdFusion generates an application exception. For more information on using the |
Note: For more information on ColdFusion error handling, see Handling Errors