Exercise 4: Providing Server-Side Validation - MACROMEDIA COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX Getting Started

Building coldfusion mx applications
Table of Contents

Advertisement

Exercise 4: Providing server-side validation

In this exercise, you will learn about the following tasks:
Creating a local variable to indicate whether data entered in the form conforms to the
Compass Travel business rules
Ensuring that a value was entered
Evaluating check box and radio button variables
Adding validation for all Compass Travel business rules
Creating a local variable
The purpose of the tripeditaction.cfm action page is to update the Compass Travel database, so it
is important to make certain that any values entered conform to all the business rules before
modifying the database. Failure of any one of the rules prevents modification of the database.
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 this example, the
variable
is set to No. The code then tests if
isOK
logic.
To create the local variable:
Open the tripeditaction.cfm file in an editor.
1.
Add the following code at the top of the file:
2.
<cfset isOk = "Yes">
Modify the file by adding the following highlighted code:
3.
<cfif isOk EQ "Yes">
<h1>Trip Added</h1>
<!--- Database insert logic goes here. --->
<cfoutput>
You have added #Form.TripName# to the trips database.
</cfoutput>
</cfif>
Save the file.
4.
tag within the action page that tests whether any of the business rules failed.
tag initializes the local variable
cfset
cfif
to Yes
isOk
.
equals Yes, before executing the SQL insert
isOk

Exercise 4: Providing server-side validation

statement:
If any rule fails, the
109

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Colfusion mx 7 - installing and using coldfusion mx

Table of Contents