Checking Query Parameters With Cfqueryparam - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

52
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.
Developing Web Applications with ColdFusion

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion 4.5

Table of Contents