System information
122 Chapter 10: Lesson 7: Validating Data to Enforce Business Rules
Reviewing the code
The following table describes the code used to verify whether the photo file exists:
Summary
As described in this lesson, ColdFusion offers a number of 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. In this lesson, you also
dynamically populated a list.
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.
Code Explanation
<cfset PhotoLocation =
"C:\CFusionMX7\wwwroot\cfdocs\
getting_started\photos\">
The cfset tag sets the value of the PhotoLocation path to
the appropriate directory.
Note: The code snippet shows one value for Windows
systems.
<cfset PhotoLocation =
PhotoLocation & FORM.photo>
The ColdFusion & operator in the cfset tag combines the
directory name with the name of the photo file entered in the
form.
<cfif not
FileExists(PhotoLocation)>
<cfset isOk = "No">
<cfoutput>
Trip Photo does not exist.
</cfoutput>
</cfif>
FileExists
checks to see if the file indicated by the
fileLocation variable exists at the specified disk location. If
it doesn’t, an error message appears.