Because you did not yet add any logic to test whether any values entered in the form are valid, the
page works precisely as before, displaying a message that indicates the database was updated,
without actually performing the update.
For more information about using the
or CFML Reference.
Ensuring that a value was entered
The first approach that you take to enforce Compass Travel business rules is to enhance the action
page to validate the data collected on the data entry form. The action page receives a form variable
for every field on the form that contains a value. You use the
fields to ensure that they adhere to Compass Travel business rules.
You can use the
cfif
tag to test whether a trip name was entered (business rule 1) on the Trip Edit form, you add the
following
statement:
cfif
<cfif Form.tripName EQ "">
<cfoutput> Trip Name cannot be blank. </cfoutput>
</cfif>
In this example, the
blank. If the trip name condition evaluates to True, ColdFusion sends the message "Trip name
cannot be blank" to the browser.
Note: The keyword EQ is an operator that tests for equality. For more information about the cfif tag
and its operators, see ColdFusion MX Developer's Guide.
To ensure that a Trip Name was entered:
Open the tripeditaction.cfm file.
1.
Enter the following code after the line
2.
<!--- Trip Name is required. --->
<cfif Form.tripName EQ "">
<CFSET IsOk = "No">
<cfoutput>Trip name cannot be blank.<br></cfoutput>
</cfif>
Save the file.
3.
To test the data validation:
Open the tripedit.cfm page in a browser.
1.
Verify that there is no value in the Trip Name field.
2.
Click Save.
3.
The error message "Trip name cannot be blank" appears.
110
Chapter 10: Lesson 7: Validating Data to Enforce Business Rules
cfset
tag to create conditions that evaluate to either True or False. To use the
statement tests to see if the value of the form variable
cfif
<cfset isOk = "Yes">
and
tags, see ColdFusion MX Developer's Guide
cfif
tag to test the values of these
cfif
.
cfif
is
tripName
Need help?
Do you have a question about the COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?
Questions and answers