System information
116 Chapter 10: Lesson 7: Validating Data to Enforce Business Rules
Modifying the Trip Edit page to use ColdFusion form tags
In this exercise, you use the ColdFusion form tags to move the validation of many business rules
from the server to the client. To do this, you change the HTML form tags in the tripedit.cfm page
to ColdFusion form tags that validate these fields on the client side. Next, you remove the
unneeded server-side single-field validation code from the tripeditaction.cfm page. Finally, you
test the form to ensure that the client-side validation is working correctly.
To use the ColdFusion form tags on the Trip Edit page:
1.
Open the tripedit.cfm file in the my_app directory in your editor.
2.
Locate and change the <form> and </form> tags to <cfform> and </cfform> tags, respectively.
3.
Change the <input> tags to <cfinput> tags, <select> tags to <cfselect> tags, and
<textarea> tags to <cftextarea> tags.
Note: The input type for the submit button must remain a standard input rather than cfinput.
4.
For each ColdFusion form tag (cfinput and cfselect), assign the following appropriate
values:
The following table contains the revised code blocks:
Attribute value Description
required Use this attribute for fields that must be filled out or selected.
validate Use this attribute for fields that require 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 appear if
validation fails. The message reflects the text that describes the business rule.
Rule Description Validation code
1 All trips must be named.
<cfinput name= "tripName"
maxlength = "50" size = "50"
required = "Yes"
message = "Trip name must not be blank">
2 All trips must be
accompanied by a full
description.
<cftextarea name="tripDescription"
required="Yes"
message="Trip description must not be blank.">
</cftextarea>
3Each trip must be
categorized by event type.
Only valid event types (1-
surfing, 2-mountain
climbing, and so on) are
permissible.
<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>
4 Trip locations are required.
<cfinput size="50" name="tripLocation"
required="Yes"
message="Trip location must not be blank.">