Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at cf.Objective() 2011 (Minneapolis, MN) with:

I Finally Used CFParam Type = "VariableName"

By Ben Nadel on
Tags: ColdFusion

I am a HUGE fan of ColdFusion's CFParam tag. I use it, I think, in a more extensive way than most people - both to enforce variable existence and to validate its data type. CFParam allows for many useful types of data type validation, including basic data types such as string, numeric, array, and struct. One type that has always struck me as weird was the type "VariableName".

I could never quite figure out why anyone would ever need to enforce a valid ColdFusion variable name. But then, yesterday, when I was working on my ColdFusion custom tag for looping over regular expression pattern matches, I had a light-bulb moment! Many ColdFusion tags (ex. CFFile, CFDirectory, CFImage, CFQuery) let you store returned data into a named variable. For example, when you run a query, the resultant record set gets stored in a variable defined by the Name attribute. All of these attributes (Name, Result, Variable) need to be valid ColdFusion variable names!

That's when all of this realization came rushing to me - any time you need to store data into a user-defined variable (as I was doing in my custom tag), you need to enforce that the value given is actually a valid ColdFusion variable name.

Of course! It's so obvious, now :)




Reader Comments

@Ray,

The one that I have really leeched onto is the IsValid( "email", FORM.email ). I used to write my own email validation function, which would fail occasionally cause people have some crazy email addresses. Luckily, IsValid( "email" ) is so much more reliable.

Reply to this Comment

@Pete,

Cool tip. I never thought of using that to help enforce logic that was necessarily FOR a variable name, but rather for values that mimic those requirements. Sweet idea.

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.