User Guide
Developing code to validate data and enforce business rules 101
4 For each ColdFusion form tag (cfinput, and cfselect), assign the appropriate values:
For example, the Trip Name field requires the following code:
<cfinput maxlength = "50" size = "50" required = "Yes" name= "tripName"
message = "Trip name must not be blank">
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.
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 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.
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">
Attribute value Description
required Use this attribute for fields that must be filled out or selected.
validate Use this attribute for fields that requires a specific data type for validation.
Values include: integer, date, time, telephone, and zip code.
message Use this attribute for fields that require an error message to be displayed if
validation fails. The message reflects the text that describes the business rule.