<cfoutput>Return date cannot precede departure date. Please re-enter.</
cfoutput>
</cfif><html>
<head>
<title>Trip Maintenance Confirmation</title>
</head>
<body>
<cfif isOk EQ "Yes">
<h1>Trip Added</h1>
<cfoutput>You have added #Form.TripName# to the trips database.
</cfoutput>
</cfif>
</body>
</html>
View the tripedit.cfm page in a browser and test the client- and server-side field validations by
7
filling out the fields on the form and clicking Save.
Testing recommendations:
Omit required fields such as trip name or location.
Make the departure date an invalid date, such as 12/32/2002.
Enter a non-numeric value in Number of People, such as one.
Using cfselect tag to present valid event types
Currently the event types in tripedit.cfm are hard-coded:
<!--- Field: eventType --->
<tr>
<td valign="top">Type of Event
</td>
<td>
<cfselect size="1" name="eventType" required="Yes" message="Type of
event must be selected.">
<option value="1" selected>Surfing</option>
<option value="2">Mountain Climbing</option>
<option value="3">Mountain Biking</option>
</cfselect>
</td>
</tr>
As described in
Lesson 1: Preparing to Build the Sample
design includes a database table that holds event types. The event type in the Trips table is an
identifier used as a foreign key to the eventtypes table (which holds the actual event names). In
the previous code, each
These values come from the eventtypes table so that they are not hard-coded. The eventtypes
table column
eventTypeID
that is displayed in the select box. To retrieve the data from this table, you must include the
following
cfquery
<cfquery name="GetEvents" datasource="CompassTravel">
SELECT eventType, eventTypeID
FROM eventtypes
</cfquery>
To exploit the query in the option tags, you can replace the HTML
102
Chapter 8: Lesson 4: Validating Data to Enforce Business Rules
tag contains a
option
is used for the value attribute and the
:
Application, the tutorial application
attribute and option text, such as
value
eventType
select
.
Surfing
for the literal value
tag with
.
cfselect
Need help?
Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?
Questions and answers