52
Developing Web Applications with ColdFusion
There are two ways to use the CFPARAM tag, depending on how you want the
validation test to proceed.
•
Use CFPARAM with only the NAME attribute to test that a required variable
exists. If it does not exist, the ColdFusion server stops processing the page.
•
Use CFPARAM with both the NAME and DEFAULT attributes to test for the
existence of an optional variable. If the variable exists, processing continues
and the value is not changed. If the variable does not exist, it is created and set
to the value of the DEFAULT attribute.
The following example shows how to use the CFPARAM tag to check for the existence
of an optional variable and to set a default value if the variable does not already exist:
<CFPARAM NAME="Form.Contract" DEFAULT="Yes">
Example: Testing for variables
Using CFPARAM with the NAME variable is a way to clearly define the variables that a
page or a custom tag expects to receive before processing can proceed. This can make
your code more readable, as well as easier to maintain and to debug.
For example, the following series of CFPARAM tags indicates that this page expects two
form variables named StartRow and RowsToFetch:
<CFPARAM NAME="Form.StartRow">
<CFPARAM NAME="Form.RowsToFetch">
If the page with these tags is called without either one of the form variables, an error
occurs and the page stops processing.
Example: Setting default values
In this example, CFPARAM is used to see if optional variables exist. If they do exist,
processing continues. If they do not exist, they are created and set to the DEFAULT
value.
<CFPARAM NAME="Cookie.SearchString" DEFAULT="temple">
<CFPARAM NAME="Client.Color" DEFAULT="Grey">
<CFPARAM NAME="ShowExtraInfo" DEFAULT="No">
You can also use CFPARAM to set default values for URL and Form variables, instead of
using conditional logic.
Checking Query Parameters with CFQUERYPARAM
You can use the CFQUERYPARAM tag to check data types of query parameters and
perform data validation.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...