Exercise 5: Validating Data On The Client Using Coldfusion Form Tags - MACROMEDIA COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX Getting Started

Building coldfusion mx applications
Table of Contents

Advertisement

To test the validation code:
View the tripedit.cfm page in the browser.
1.
In the form, enter 500 in both the Price and Base Cost fields.
2.
Click the Save button.
3.
The trip price error message displays: "Price must be marked up at least 20% above cost."
Click the browser Back button to return to the tripedit.cfm page.
4.
To avoid the error, enter 800 in the Price field, and click Save.
5.
Test various combinations to ensure that all the Compass Travel business rules are enforced by
6.
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 checkbox
Data" in ColdFusion MX Developer's Guide.
114
Chapter 10: Lesson 7: Validating Data to Enforce Business Rules
,
, and others. For more information, see Chapter 28, "Validating
cfselect
,
cfinput text
cfinput radio
,

Advertisement

Table of Contents
loading

This manual is also suitable for:

Colfusion mx 7 - installing and using coldfusion mx

Table of Contents