I Finally Used CFParam Type = "VariableName"

Posted September 26, 2007 at 2:44 PM by Ben Nadel

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 :)


You Might Also Be Interested In:



Reader Comments

Sep 26, 2007 at 3:23 PM // reply »
319 Comments

You can also use isValid("variablename", somevar).


Sep 26, 2007 at 3:48 PM // reply »
11,238 Comments

Good call. I don't use IsValid() enough.


Sep 26, 2007 at 3:51 PM // reply »
319 Comments

It was one of the 'gems' overlooked in CF7. Very handy stuff.


Sep 26, 2007 at 3:58 PM // reply »
44 Comments

I go IsValid crazy in ICEGen. IsValid is probably the most useful function ever entered into the ColdFusion family.


Sep 26, 2007 at 3:59 PM // reply »
11,238 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.


Sep 26, 2007 at 6:23 PM // reply »
15 Comments

I use type = variablename quite a bit actually... It is much better than just using type = string when you are dealing with simple string values (one word values), it also requires that the string is not zero length...

Here's a blog entry I did on this a while back: http://www.petefreitag.com/item/632.cfm


Sep 27, 2007 at 7:10 AM // reply »
11,238 Comments

@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.


Post A Comment

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.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 21, 2013 at 7:46 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
No luck. At least I have uncovered the cause, URLScan 3.1. Here is what I see in the IIS log when a file is over 30mb. 2013-05-21 23:29:05 10.105.45.128 GET /plupload/assets/jquery/jquery-1.8. ... read »
May 21, 2013 at 6:12 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
Ben, I did not see you after Pete Freitag's Lockdown session at cfObjective but he said that IIS sets file size limits at 30MB by default which just happened to be the threshold for file size when ... read »
May 21, 2013 at 11:51 AM
Ask Ben: Parsing Very Large XML Documents In ColdFusion
Looking at my first ever XML document that I have to parse and put into MS SQL 2000 with CF8. I get it to list the desired Field name, many times over, and have a long list of this field name displa ... read »
May 21, 2013 at 9:25 AM
Turning Off and On Identity Column in SQL Server
you are awesome..i am lucky to get this blog between such a garbage one....Thanks, Prashant ... read »
May 20, 2013 at 4:38 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, Your confusion is well founded, since this is a very confusing features. In fact, it ONLY works if you use array notation. Meaning, that this: arrayToList( query[ "columnName" ] ) ... read »
May 20, 2013 at 4:34 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I was thinking chicken and the egg, I wouldn't have expected it to work in the valuelist going in I guess. Maybe I just need a beer, long day :) ... read »
May 20, 2013 at 4:29 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, That's if you're trying to reference a specific row. In this case, we're trying to reference the entire query column as one cohesive value. So, you are correct that if you wanted to output a ... read »
May 20, 2013 at 4:24 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I thought when you used array notation to reference queries you always had to have the row or it would throw a similar error as well? ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools