Using <cfparam> Server-Side Validation

One solution to the proliferation of <cfif> statements in Listing 13.2 is to use the <cfparam> tag (first introduced in Chapter 9, “Programming with CFML”). The <cfparam> tag has two distinct functions:

  • Providing default values for variables

  • Performing field value validation

The difference is whether or not a default is provided. Look at this example:

<cfparam name="LoginID">

No default value is provided, and so LoginID is required, and if not present an error will be thrown.

By contrast, this next example has a default value:

<cfparam name="color" default="red">

In this example color isn’t required, and if not present, the default value of red will be used.

<cfparam> also supports one additional attribute, ...

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.