MACROMEDIA COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX Getting Started page 97

Building coldfusion mx applications
Table of Contents

Advertisement

Evaluating check box and radio button variables
Business rule 8 in the Compass Travel new trip policy requires you to test the value of the
check box form variable. Check box and radio button variables are only passed
depositRequired
to the action page when the user selects these options on the form. Therefore, an error occurs if
the action page tries to use a variable that was not been passed.
To insure an error does not occur, you will use the
determine whether the user selected the Deposit Required check box option on the form:
<cfif not IsDefined("Form.depositRequired")>
<cfset form.depositRequired = "No">
</cfif>
The
statement and the
cfif
to determine if a value exists. The statement
depositRequired
the specified variable is not found and the
indicates a deposit is not required; Yes indicates a deposit is required.
Evaluating whether business rules fail
The purpose of the tripeditaction.cfm action page is to update the Compass Travel database, so it
is important to make certain that all the business rules are passed successfully before the database
insert is executed. Failure of any one of the rules negates the insert.
One approach to ensuring that the action page considers each business rule is to create a local
variable with a
cfset
The
tag lets you manipulate the value of a variable. For example, the following pseudocode
cfset
initializes a variable to a specific value and checks the value using the
<cfset isOk = "Yes">
if rule 1 fails then
<cfset isOK = "No"
...
if Rule n fails then
<cfset isOk = "No">
...
<cfif isOk = "Yes">
update the database
</cfif>
In the previous example,
variable
is set to No. The code then tests if
isOK
logic.
For more information about using the
Developing ColdFusion MX Applications or CFML Reference.
Exercise: create an action page with server-side validation
In this exercise you build an action page (tripeditaction.cfm)to validate the data passed to
ColdFusion MX from the tripedit.cfm data entry page. You use the
edits that ensure the data passed is valid per the Compass Travel business rules. Additionally, you
will use the ColdFusion
form (tripedit.cfm).
function evaluate the value of the form variable
IsDefined
cfset
tag within the action page that tests to see if any of the business rules failed.
initializes the local variable
cfset
cfset
function to check to see if data was entered in the data entry
IsDefined
Developing code to validate data and enforce business rules
function in a
IsDefined
not IsDefined
statement sets the form variable to No. No
to Yes
isOk
equals Yes, before executing the SQL insert
isOk
and
tags and the
cfif
cfif
statement to
cfif
returns True if
statement:
cfif
If any rule fails, the
.
function, see
IsDefined
and c
tags to build
fset
97

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents