Revisiting Variables

Another important tag is <cfparam>. You won’t use this tag here, but in preparation for the next chapters, I’ll explain what this tag is and how it is used.

Earlier in this chapter, you used a function named IsDefined(), which is used to check whether a variable exists. You used IsDefined() to simply check for a variable’s existence, but what if you wanted to create a variable with a default value if it did not exist? You could do something similar to this:

<cfif NOT IsDefined("FirstName")>
 <cfset FirstName="Ben">
</cfif>

Why would you want to do this? Well, as a rule, you should not include data validation code in the middle of your core code. This is bad practice for several reasons, the most important of which are that ...

Get Adobe ColdFusion 8 Web Application Construction Kit, Volume 1: Getting Started now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.