# 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 "Client.Email " or "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. "

Type Values
Type Value | Description
--- | ---
any | any value.
array | any array value.
binary | a binary value.
boolean | a Boolean value.
date | a date-time value.
numeric | a numeric value.
query | a query object.
string | a string value or a single character.
struct | a structure.
UUID | a Universally Unique Identifier (UUID) formatted as `XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXX' where `X' stands for a hexadecimal digit (0-9 or A-F). See CreateUUID.
variableName | a valid variable name.

#### DEFAULT

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

### 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 --->
            <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>