User Guide

96 Chapter 8: Lesson 4: Validating Data to Enforce Business Rules
The following table lists the Compass Travel business rules for capturing and editing trip
information. This table identifies which rules require single-field or cross-field editing.
Ways to validate data
ColdFusion provides special tags to simply the process of enforcing business rules. Using
ColdFusion, it is possible to enforce business rules in several places. For example, you can enforce
some validation edits on the client. Other validation edits, you can enforce on the server after the
data entry form is submitted. You will explore these options in the following sections.
Validating data using a server-side action page
The first approach you will take to enforce Compass Travel business rules is to develop an action
page to validate the data collected on the data entry form. The action page receives a form variable
for every field on the form that contains a value. You use the
cfif tag to test the values of these
fields to ensure that they adhere to Compass Travel business policy.
Using a cfif tag to enforce business rules
The
cfif tag lets you create conditions that evaluate to either True or False. Therefore, to use the
cfif tag to test whether a trip name was entered (business rule 1)on the Trip Edit form, you code
the following cfif statement:
<cfif Form.tripName EQ "">
<cfoutput> Trip Name cannot be blank. </cfoutput>
</cfif>
In the previous example, the cfif statement tests to see if the value of the form variable tripName
is blank. If the trip name condition evaluates to True, ColdFusion sends "Trip name cannot be
blank" to the browser.
Note: The keyword EQ is an operator used to test for equality. For more information about the cfif
tag and its operators, see Developing ColdFusion MX Applications.
Compass Travel new trip policy Edit type
1 All trips must be named. Single-field
2 All trips must be accompanied by a full description. Single-field
3 Each trip must be categorized by event type. Only valid event types (1-surfing, 2-
mountain climbing, and so on) are permissible
Single-field
4 Trip locations are required. Single-field
5 The maximum number of people permitted on the trip must be specified. Single-field
6 The trip departure and return dates must be specified for each trip.
All trip dates must be valid future dates. Departure date must precede return date.
Single-field
Cross-field
7 The trip’s price and base cost are required. Both values are positive numeric
values. The trip price must have at least a 20% markup over base cost.
Cross-field
8 Any trip priced over $750 requires a deposit. Cross-field
9 A trip leader must be identified. Single-field
10 A photo must accompany all new trips. The photo image file must reside within
the images directory of the Compass Travel website.
Single-field