114
Chapter 10: Lesson 7: Validating Data to Enforce Business Rules
To test the validation code:
1.
View the tripedit.cfm page in the browser.
2.
In the form, enter
500
in both the Price and Base Cost
fields.
3.
Click the Save button.
The trip price error message displays: "Price must be marked up at least 20% above cost."
4.
Click the browser Back button to return to the tripedit.cfm page.
5.
To avoid the error, enter
800
in the Price field, and click Save.
6.
Test various combinations to ensure that all the Compass Travel business rules are enforced by
filling out the fields on the form and clicking Save.
Testing recommendations:
■
Leave out required fields, such as trip name or location.
■
Enter a nonnumeric value in Number of People, such as
one
.
■
Leave the entire form blank and click Save. The following messages appear:
Trip name cannot be blank. A trip leader must be specified. Photo filename must be
specified. The number of people must be a number and cannot be blank. Trip location
cannot be blank. Base cost must be a number and cannot be blank. Price must be a number
and cannot be blank.
Exercise 5: Validating data on the client using ColdFusion form
tags
In this exercise, you will compare server-side and client-side validation. You then modify the
testedit.cfm page to use client-side scripting.
Comparing server-side and client-side validation
Validating data on the server-side has two drawbacks. First, the action page is used for validation,
so the
form page is not in the browser context when the error is trapped. The user, therefore, will
not get immediate feedback from the page where the data was entered. Second, because data
capture occurs on the client and validation occurs on the server, the number of round-trips to the
server is increased. This can cause increased traffic on the network and the server. If the data is
validated on the client, only valid data is posted to the server and traffic is reduced.
An alternative approach to server-side editing is to use client-side scripting. Client-side scripting
lets you validate the form data entered on the client prior to posting it to the server. CFML
provides alternative versions of standard HTML form tags, which provide the advantages of
client-side data validation. These data input tags include
cfinput
text
,
cfinput
radio
,
cfinput
checkbox
,
cfselect
, and others. For more information, see Chapter 28, “Validating
Data” in
ColdFusion MX Developer’s Guide
.
Содержание COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 14: ...14 Chapter 1 Introducing ColdFusion MX...
Страница 38: ...38 Chapter 3 Database Fundamentals...
Страница 40: ......
Страница 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Страница 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Страница 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Страница 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Страница 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...