Adobe ColdFusion 8

Using the cfparam tag

You can ensure that a variable exists by using the cfparam tag, which tests for the variable's existence and optionally supplies a default value if the variable does not exist. The cfparam tag has the following syntax:

<cfparam name="VariableName"
    type="data_type"
    default="DefaultValue">

Note: For information on using the type attribute to validate the parameter data type, see the CFML Reference.

There are two ways to use the cfparam tag to test for variable existence, depending on how you want the validation test to proceed:

  • With only the name attribute to test that a required variable exists. If it does not exist, the ColdFusion server stops processing the page and displays an error message.
  • With 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, and processing continues.

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