Developing code to validate data and enforce business rules
99
6
Test various combinations to make sure 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 non-numeric 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.
Drawbacks of validating data on the server-side
Validating data on the server-side has two drawbacks. First, since the action page is used for
validation, the
form page is not in the browser context when the error is trapped. The user will,
therefore, not get immediate feedback from the page where the data was entered. Second, because
data capture occurs on the client and validation 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, then only valid data is posted to the server and traffic is reduced.
Validating data on the client using ColdFusion form tags
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 that provide advantages of client-side
data validation.These data input tags include
cfinput text
,
cfinput radio
,
cfinput
checkbox
,
cfselect
, and others.
Among the improvements over standard HTML tags, ColdFusion form tags offer the following
attributes:
Examples of using the improved ColdFusion form tags
To use the improved form tags, you must replace the HTML form tag with the
cfform
tag. The
following code snippets show the use of the improved ColdFusion form tags. The first code
snippet shows how the duration field is validated on the server. The second code snippet shows
how ColdFusion form tags simplify field validation on the client.
Attribute
Description
validate
The data type that the field tag validates against. Values include: integer, date, time,
telephone, zipcode.
message
The error message displayed if validation fails.
range
The range of permissible values for this tag.
required
An indicator of whether data is required for the corresponding tag.
Содержание COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 30: ...30 Chapter 2 CFML Basics...
Страница 36: ...36 Chapter 3 Database Fundamentals...
Страница 48: ......
Страница 76: ...76 Chapter 6 Lesson 2 Writing Your First ColdFusion Application...
Страница 134: ...134 Index...