Programming instructions

Developing code to validate data and enforce business rules 103
Developing code to validate data and enforce business
rules
As described in Lesson 1, it is important to define the right data type for each column on
the tables in the database. A fundamental concern, therefore, is ensuring that the
captured data is suitable for the column definitions in the Trips table. This type of
validation on a single field is often referred to as a single-field edit.
Compass Travel has other operating policies that involve evaluating the values from more
than one field. These validations, referred to as cross-field edits, are usually more difficult
to program. To assure that new trips are uniformly captured, Compass Travel has
published cross-field validations and single-field edits in its Compass Travel business
rules.
The following table lists the Compass Travel business rules for capturing and editing trip
information. This table identifies which rules requiring single 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.
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