MACROMEDIA COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX Getting Started page 98

Building coldfusion mx applications
Table of Contents

Advertisement

To build trip edit action page and validate data passed:
Open an editor and create a new page called tripeditaction.cfm in the my_app directory. The
1
new page appears as follows:
<html>
<head>
<title>Untitled</title>
</head>
<body>
</body>
</html>
To ensure that Compass Travel business rule 7 is met, insert the following code above the
2
tag on the tripeditaction.cfm page. For your convenience, business rule 7 is repeated.
<html>
Business rule 7
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><br>
</cfif>
</cfif>
Note: The code for business rule 7 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 Developing ColdFusion MX Applications.
Save the page.
3
Use the following steps to test the code to see if it meets the objective of business rule 7:
4
View the tripedit.cfm page in the browser.
a
In the form, enter the number 500 in both the Price and Base cost fields.
b
Click the Save button.
c
The trip price error message displays: "Price must be marked up at least 20% above cost."
Click the browser Back button to return to the tripedit.cfm page.
d
To avoid the error, enter the number 800 in the Price field and click Save.
e
Complete all the business rules using server-side validation. You must insert the code for each
5
business rule above the
solutions directory.
Tip: You can either modify your new tripeditaction.cfm page to include the code necessary to
meet all ten business rules or you can copy the tripeditaction1.cfm page from the solutions
directory to tripeditaction.cfm in the my_app directory.
98
Chapter 8: Lesson 4: Validating Data to Enforce Business Rules
: The trip's price and base cost are required. Both values are positive numeric
tag. As an example, see the tripeditaction1.cfm page in the
<html>

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents