Before relying on a variable's existence in an application page, you can test to see if it exists using the ColdFusion IsDefined
function. A function is a named procedure that takes input and operates on it. For example, the IsDefined
function determines whether a variable exists. CFML provides a large number of functions, which are documented in CFML Reference.
The following code prevents the error in the previous example by checking to see whether the Contractor Form variable exists before using it:
<cfif IsDefined("Form.Contractor")>
<cfoutput>Contractor: #Form.Contractor#</cfoutput> </cfif>
The argument passed to the IsDefined
function must always be enclosed in double-quotation marks. For more information on the IsDefined
function, see CFML Reference.
If you attempt to evaluate a variable that you did not define, ColdFusion cannot process the page and displays an error message. To help diagnose such problems, turn on debugging in the ColdFusion MX Administrator. The Administrator debugging information shows which variables are being passed to your application pages.