isDefined() and <cfparam>

Contact Us or call 1-877-932-8228
isDefined() and <cfparam>

isDefined() and <cfparam>

ColdFusion errors when it is asked to try to evaluate an undefined variable. In some cases, you will want to check to see whether a variable is defined before trying to evaluate it. You can use the isDefined() function to check this.

<cfif isDefined("Form.firstname")> <cfoutput>Hello, #Form.firstname#!</cfoutput> <cfelse> Hello, stranger! </cfif>

In other cases, you will want to set a default value for a variable in case it is accessed before it is explicitly defined. Use <cfparam> for this.

<cfparam name="Form.firstname" default="stranger"> <cfoutput>Hello, #Form.firstname#!</cfoutput>

In the example above, if Form.firstname is defined before the <cfparam> tag is reached, then the <cfparam> tag would be ignored. Otherwise, the default value of stranger would be assigned to Form.firstname.

Next