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

Building coldfusion mx applications
Table of Contents

Advertisement

Reviewing the code
The following table describes the code used to properly initialize the trip edit form:
Code
<cfif IsDefined("URL.ID")>
<cfquery name="TripQuery" datasource="CompassTravel"
maxrows="1">
SELECT tripName, eventType, tripDescription,
tripLocation, departureDate, returnDate, price,
tripLeader, photo, baseCost, numberPeople,
depositRequired, tripID
FROM trips
<cfif IsDefined("URL.ID")>
WHERE tripID = #ID#
</cfif>
</cfquery>
<!-- Set the local variables -->
<cfset tripName = '#TripQuery.tripName#'>
<cfset eventType = #TripQuery.eventType#>
<cfset tripDescription =
TripQuery.tripDescription#'>
<cfset tripLocation = '#TripQuery.tripLocation#'>
<cfset departureDate =
DateFormat(#TripQuery.departureDate#,"mm/dd/yyyy")>
<cfset returnDate =
DateFormat(#TripQuery.returnDate#,"mm/dd/yyyy")>
...
<cfelse>
<cfset tripName = ''>
<cfset eventType = ''>
...
</cfif>
Exercise: linking the Add and Edit buttons
In this exercise you will link the Add and Edit buttons on the Trip Detail page with the Trip Edit
page.
To link the add and update buttons on the Trip Detail page:
Open maintenanceaction.cfm in the my_app directory in your editor.
1
Locate the
2
</cfif>
Insert the following code just before the last line:
3
<!---
EDIT BUTTON --->
<cfelseif IsDefined("Form.btnEdit")>
<cflocation url="tripedit.cfm?ID=#Form.RecordID#">
<!---
ADD BUTTON --->
<cfelseif IsDefined("Form.btnAdd")>
<cflocation url="tripedit.cfm">
Save maintenanceaction.cfm.
4
Open tripedit4.cfm in the solutions directory in your editor.
5
Open the file initvariables.txt from the solutions directory.
6
Copy the contents of the initvariables.txt and paste it before the
7
page.
Save the file as tripedit.cfm in the my_app directory.
8
tag at the end of the file.
Explanation
The ColdFusion function
determines whether an ID argument
was passed as part of the invoking
URL.
The ID argument is passed when
TripEdit is invoked when the Edit
button is clicked on the main page.
When an ID is passed, it is used in the
WHERE clause of the SQL SELECT
statement to retrieve the information
about the current trip. The program
then instantiates local variables from
the results of the SQL query. The
ColdFusion
formats the date fields.
If TripEdit is called to add a new trip,
then there is no ID passed as a URL
argument. In this case, the local
variables are instantiated to blank.
<HTML>
Completing the Trip Maintenance application
IsDefined
function
DateFormat
tag in the tripedit4.cfm
127

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

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents