The following considerations affect the validation technique that you select:
The preceding table in the Validation techniques section described some of the considerations. The following table describes additional considerations for selecting a validation technique. For additional considerations that are specific to form fields, see Validation type considerations.
Validation technique | Features | Considerations | Security issues |
---|---|---|---|
mask ( |
Directly controls user input. |
Limited to |
In HTML and XML format, can be circumvented because JavaScript runs directly in the browser. |
onBlur (
|
Provides immediate feedback if a user enters invalid data. |
Limited to |
In HTML and XML format, can be circumvented because JavaScript runs directly in the browser. |
onSubmit (
|
All entered data is available to the user; only the invalid data needs reentering. |
Limited to |
In HTML and XML format, can be circumvented because JavaScript runs directly in the browser. |
onServer (
|
Does not require browser support. |
Limited to |
Can be circumvented because validation rules are submitted with the form. |
Hidden form field |
Does not require browser support. Can be used with HTML or CFML form elements. |
Limited to forms. |
Can be circumvented because validation rules are submitted with the form. |
JavaScript ( |
Allows all on-client processing supported by the browser. Can be used with HTML or CFML form elements. |
Limited to specific ColdFusion form tags. Calls a single JavaScript function. JavaScript levels of support can vary among browsers, and users can disable JavaScript in their browsers. |
Can be circumvented because JavaScript runs directly in the browser. |
|
Can be used for any variable, not just form fields. Returns a Yes or No result that you use to determine further processing. |
When used with a form field, runs after the data is submitted. Must be used each time a variable needs to be validated. Provides some data type checks not available in forms validation techniques. |
None |
|
Can be used for any variable, not just form fields. The tag can set a default value in addition to validating data. |
When used with a form field, the tag runs after the data is submitted. You respond to validation failures using error-handling code. |
None |
|
Used for arguments to functions written using the |
Runs when the function is called on the server. You respond to validation failures using error-handling code. |
None |
Although form-specific validation techniques provide good methods for preventing users from submitting invalid or badly formatted data, they cannot prevent users from submitting maliciously formatted data from HTML forms. Malicious users can circumvent validation techniques that require validation on the browser using JavaScript or submission of validation rules in hidden fields. If you must use a technique for preventing malicious data submissions, consider using the following techniques:
onSubmit
or OnBlur
validation in Flash forms, which use Flash built-in validation.
cfparam, and cfargument tags, which let you test variables and arguments in your CFML code.
cfqueryparam
tag in cfquery
tags, described in Enhancing security with cfqueryparam, which can help protect databases from malicious query input.
scriptprotect
attribute. For more information on cross-site scripting attacks and this option, see the cfapplication tag page in the CFML Reference.