CFPARAM

CFPARAM is used to test for a parameter's existence, and optionally test its data type, and provide a default value if one is not assigned.

Syntax

<CFPARAM NAME="param_name"
    TYPE="data_type">
    DEFAULT="value">

NAME

The name of the parameter you are testing (such as "Cookie.BackgroundColor"). If you omit the DEFAULT attribute, an error occurs if the specified parameter does not exist.

TYPE

Optional. The type of parameter that is required. The default value is "any."

DEFAULT

Optional. Default value to set the parameter to if it does not exist.

Usage

There are three ways to use CFPARAM:

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 --->
        <CFSET tempVar = 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>

<P>
<FORM ACTION="cfparam.cfm" METHOD="POST">
Type in a new value for tempVar, and hit submit:<BR>
<INPUT TYPE="Text" NAME="tempVar">

<INPUT TYPE="Submit" NAME="" VALUE="submit">

</FORM>

</BODY>
</HTML>