IsDefined

Description

Evaluates a string value to determine whether the variable named in it exists.

This function is an alternative to the ParameterExists function, which is deprecated.

Returns

True, if the variable is found; False, otherwise.

Function syntax

IsDefined("variable_name")

See also

Evaluate

History

ColdFusion MX: Changed behavior: this function can process only the following constructs:

  • A simple variable

  • A named variable with dot notation

  • A named structure with dot notation (for example: mystruct.key)

Parameters

Parameter

Description

variable_name

String, enclosed in quotation marks. Name of variable to test for.

Usage

Passing an array entry, such as myArray[3] to this function causes an error. To check whether a specific entry exists in an array, use the ArrayIsDefined function.

You can test whether a specific key exists in a structure by using this function or the StructKeyExists function. For example, when working with scopes that ColdFusion exposes as structures, the StructKeyExists function can sometimes replace this function. The following lines are equivalent:

if(isDefined("form.myVariable")) 
if(structKeyExists(form,"myVariable"))

Example

<cfif IsDefined("form.myString")> 
    <p>The variable form.myString has been defined, so show its contents. 
    This construction allows us to place a form and its resulting action code 
    on the same page and use IsDefined to control the flow of execution.</p> 
    <p>The value of "form.myString" is <b><i> 
    <cfoutput>#form.myString#</cfoutput></i></b> 
<cfelse> 
    <p>During the first time through this template, the variable "form.myString"  
    has not yet been defined, so we do not try to evaluate it. 
</cfif> 
 
<form action="#CGI.Script_Name" method="POST"> 
<input type="Text" name="MyString" value="My sample value"> 
<input type="Submit" name=""> 
</form>