108
Chapter 8: Lesson 4: Validating Data to Enforce Business Rules
To verify that the photo filename exists:
1
Open the tripeditaction.cfm in the my_app directory in your editor.
2
In the tripeditaction.cfm page, do the following:
a
Add logic to check that the user entered a valid photo filename by copying the code from
the photofilecheck.txt file in the solutions directory pasting it immediately following the
first <cfset isOk = "Yes"> statement.
b
Verify that code you copied in step a is pointing to the correct photolocation path. The path
is specified in the <cfset PhotoLocation = "C:..."> tag.
For example, depending on your web server configuration, the photolocation path might
be:
■
For MS Windows systems:
<cfset PhotoLocation
"C:\cfusionmx\wwwroot\cfdocs\getting_started\photos\">
or
<cfset PhotoLocation =
"C:\Inetpub\wwwroot\cfdocs\getting_started\photos\">
■
For Linux or Solaris systems:
<cfset PhotoLocation =
"/opt/cfusionmx/wwwroot/cfdocs/getting_started/photos/">
or
<cfset PhotoLocation =
"/<webserverdocroot>/cfdocs/getting_started/photos/">
3
Save the page and test it by opening the tripedit.cfm page in your browser.
Testing recommendations:
a
In the Trip Edit page, enter valid information in all the required fields but the Photo File
field.
b
In the Photo File field, enter nowhere.jpg and click Save.
The following error message appears: Trip photo does not exist.
c
To avoid the error, replace the invalid photo filename in the Trip Edit page with
somewhere.jpg and click Save.
The following message appears: Trip added.
Summary
As described in this lesson, ColdFusion offers several alternatives to validating data. If you are
familiar with standard page validation code, ColdFusion supports these development approaches.
However, ColdFusion form tags simplify data validation.
Additionally, you can use JavaScript
with ColdFusion to execute client-side functions.
In the next lesson
Now that you are sure that your application can save valid data, in the next lesson, you will write
code to add trips to the database. Additionally, you will add logic to update existing trip data in
the Trips table.
Содержание COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 30: ...30 Chapter 2 CFML Basics...
Страница 36: ...36 Chapter 3 Database Fundamentals...
Страница 48: ......
Страница 76: ...76 Chapter 6 Lesson 2 Writing Your First ColdFusion Application...
Страница 134: ...134 Index...