System information
118 Chapter 10: Lesson 7: Validating Data to Enforce Business Rules
5.
Open the tripeditaction.cfm file in the my_app directory and delete the code for the following
single-field validation rules:
■ Trip name is required.
■ Trip description is required.
■ Trip leader is required.
■ Photo filename 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.
6.
Save the file.
The modified tripeditaction.cfm page appears as follows:
<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>
</body>
</html>