System information

Exercise 4: Providing server-side validation 113
Note: The code for business rules 7 and 8 uses ColdFusion cfif and cfelse conditional processing
tags. The code inside the
cfif tags only executes when the condition evaluates to True. To perform
other actions when the condition evaluates to False, the
cfelse tag is used. For more information
about using conditional processing tags, see ColdFusion MX Developer’s Guide.
7 The trip’s price and base cost
are required. Both values are
positive numeric values. The
trip price must have at least a
20% markup over base cost.
<!--- Base Cost is required and must be numeric. --->
<cfif Form.baseCost EQ "" or
IsNumeric(Form.baseCost) EQ False>
<cfset IsOk = "No">
<cfoutput>
Base Cost must be a number and cannot be
blank.
</cfoutput>
<cfelse>
<!--- Price must be 20% greater than Base Cost. --->
<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>
8 Any trip priced over $750
requires a deposit.
<!--- Price is required and must be numeric. --->
<cfif Form.price EQ "" or
IsNumeric(Form.baseCost) EQ False>
<cfset IsOk = "No">
<cfoutput>
Price must be a number and cannot be blank.
</cfoutput>
<cfelse>
<!--- A deposit is required when the price is >
$750. --->
<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>
9 A trip leader must be identified.
<!--- Trip Leader is required. --->
<cfif Form.tripLeader EQ "">
<cfset IsOk = "No">
<cfoutput>
A trip leader must be specified.
</cfoutput>
</cfif>
10 A photo must accompany all
new trips.
<!--- Photo filename is required. --->
<cfif Form.photo EQ "">
<cfset IsOk = "No">
<cfoutput>
Photo filename must be specified.</cfoutput>
</cfif>
Rule Description Validation code