152
Usage
There are three ways to use CFPARAM:
Test for a required variable — Use CFPARAM with only the NAME attribute to
test that a required variable exists. If the variable does not exist, ColdFusion
server stops processing the page and returns an error.
Test for a required variable and for the type of variable — Use CFPARAM with
the NAME attribute and the TYPE attribute to test that a required variable
exists, and that it is of the specified type.
Test for an optional variable — 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.
Example
<!--- This example shows how CFPARAM operates --->
<CFPARAM NAME="storeTempVar" DEFAULT="my default value">
<CFPARAM NAME="tempVar" DEFAULT="my default value">
<!--- check if form.tempVar was passed --->
<CFIF IsDefined("form.tempVar") is "True">
<!--- check if form.tempVar is not blank --->
<CFIF form.tempVar is not "">
<!--- if not, set tempVar to value of form.tempVar --->
</CFIF>
</CFIF>
<HTML>
<HEAD>
<TITLE>
CFPARAM Example
</TITLE>
</HEAD>
<BODY bgcolor=silver>
<H3>CFPARAM Example</H3>
<P>CFPARAM is used to set default values so that
the developer does not need to check for the existence
of a variable using a function like IsDefined.
<P>The default value of our tempVar is "<CFOUTPUT>#StoreTempVar#
</CFOUTPUT>"
<!--- check if tempVar is still the same as StoreTempVar
and that tempVar is not blank --->
<CFIF tempVar is not #StoreTempVar# and tempVar is not "">
<H3>The value of tempVar has changed: the new value
is <CFOUTPUT>#tempVar#</CFOUTPUT></H3>
</CFIF>
<CFSET tempVar = form.tempVar>
CFML Language Reference
Need help?
Do you have a question about the COLDFUSION 4.5-CFML LANGUAGE and is the answer not in the manual?