Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion isDefined

Tags:

coldfusion

I am trying to check to see if data exist in my form If data does not exist I want to assign it to O. How can I do this.

<cfif not isDefined("FORM.Age")>
 cfset FORM.Age = "0"
<cfif>
like image 686
user2967577 Avatar asked Nov 08 '13 04:11

user2967577


1 Answers

Generally the best practice is considered to be to avoid isDefined. This is because isDefined will search all scopes until it finds a matching variable. So it's more efficient to use structKeyExists, eg:

<cfif NOT structKeyExists(form, "age")>
   <cfset form.age = 0>
</cfif>

Also, another way to achieve this is to use cfparam, and specify 0 as the default:

<cfparam name="form.age" default="0">
like image 81
Andrew Myers Avatar answered Sep 27 '22 22:09

Andrew Myers