Programming instructions

Developing code to validate data and enforce business rules 109
Tip: For additional help, review the completed code in the tripedit2.cfm within the
solutions directory. For more details about using ColdFusion form tags and their
attributes, see Developing ColdFusion MX Applications with CFML.
5 In your editor, open the tripeditaction.cfm in the my_app directory and delete the
code for the following single-field validation rule:
Trip name is required.
Trip leader is required.
Photo file name is required.
Number of people is required and must be numeric.
Trip location is required.
Base cost is required and must be numeric.
Price is required and must be numeric.
Tip: You can either remove the single-field validations yourself or use
tripeditaction2.cfm file in the solutions directory. The file tripeditaction2.cfm in the
solutions directory is a copy of tripeditaction with the single-field edits deleted. Copy
tripeditaction2.cfm in the solutions directory to tripeditaction.cfm in the my_app
directory.
6 When you finish deleting the single-field validation rules, save the file.
The modified tripeditaction.cfm page appears as follows:
<!--- Action Page to edit and save Trip information for Compass Travel. --->
<!--- Single field edits have been removed in favor of client-side edits. --->
<!--- Make the passportRequired variable be No if it is not set
(check box is empty) --->
<cfset isOk = "Yes">
<cfif not isdefined("Form.depositRequired")>
<cfset form.depositRequired = "No">
</cfif>
<cfif Form.price GT 750 AND Form.depositRequired EQ "No">
<cfset IsOk = "No">
<cfoutput>Deposit is required for trips priced over $750.</cfoutput>
</cfif>
<cfif Form.basecost * 1.2 GT #Form.price#>
<cfset IsOk = "No">
<cfoutput>Price must be marked up at least 20% above cost.</cfoutput>
</cfif>
<cfif form.departureDate GT form.returnDate>
<cfset isOk = "No">
<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>