Developing code to validate data and enforce business rules
95
Exercise: view the source and test the Trip Edit page
To view the source and test the Trip Edit data collection form:
1
Open an editor, then locate and open the file tripedit1.cfm in the solutions directory
\cfdocs\getting_started\solutions under your web root directory.
2
Review the HTML source code used to create the Trip Edit page. If you are not fluent in
HTML, the following table explains the use of some of the HTML tags in the Trip Edit page.
For more information on HTML, consult any HTML primer.
3
Save the file as tripedit.cfm to the my_app directory.
4
View the tripedit.cfm in a browser and test the form by entering a trip name in the Trip Name
field then clicking Save. An error occurs.
5
View the form source (tripedit.cfm) in an editor to try to determine the cause of the error.
Notice that the
<form>
tag on line 6 of the source code has an
action
attribute. This attribute
indicates the page to receive the form values posted by the tripedit.cfm page. Since the page,
tripeditaction.cfm, does not exist yet, ColdFusion MX sends an error.
At this point, this form does not store any information in the database and does not enforce any
business rules of Compass Travel. In the next exercise, you will develop the action page to enforce
the business rules.
Developing code to validate data and enforce business rules
As described in
Lesson 1: Preparing to Build the Sample Application
, 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.
Tag Description
Form
You create a data entry form by using the
form
tag. The
form
tag takes two tag
attributes; for example:
<form action="tripeditaction.cfm" Method= "Post">
Here, the
action
attribute specifies the name of the ColdFusion file that the web
server will navigate to in response to the form’s submission. The
method
attribute
specifies how data is returned to the web server. Submit all ColdFusion forms using
the
Post method
attribute.
Table
You can format a data entry form and display its controls neatly, by using the table
tag,
table
, table row tag,
tr
, and the table data tag,
td
.
Form
Controls
The form requires controls to collect and submit user input. There are a variety of
types of form controls you can use. For this lesson, you will use the following
controls:
•
<input>
Accepts text answers such as Trip Name and Trip Price.
•
<input type=checkbox>
Asks yes or no questions, such as Deposit Required?
•
<select>,<option>
Provides user with a list of possible answers such as the
event type (Mountain Biking, Surfing, and so on).
•
<textarea>
Gathers user input on multiple lines such as for the Trip Description.
•
<input type=submit>
Posts the information collected to the server.
Содержание 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...