Exercise 6: Inserting Values In The Edit Form - MACROMEDIA COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX Getting Started

Building coldfusion mx applications
Table of Contents

Advertisement

Insert the highlighted code:
3.
<cfelseif IsDefined("Form.btnEdit")>
<!--- Code to execute if the user clicked Edit. --->
<cflocation url="tripedit.cfm?ID=#Form.RecordID#">
<cfelseif IsDefined("Form.btnAdd")>
<!--- Code to execute if the user clicked Add. --->
<cflocation url="tripedit.cfm">
Save the file.
4.

Exercise 6: Inserting values in the edit form

Notice that when the user clicks the Add button, the maintenanceaction.cfm page navigates to
the tripedit.cfm page without passing any arguments. Conversely, when the user clicks the Edit
button, the Trip Edit page passes the current record ID. The Trip Edit page must handle both
cases. When a
RecordID
fill the form with the data for the corresponding trip.
To insert values in the edit form:
Open the tripedit.cfm file in your editor.
1.
Enter or copy and paste the following code after the
2.
the file:
<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 = #url.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")>
<cfset price = #TripQuery.price#>
<cfset tripLeader = '#TripQuery.tripLeader#'>
<cfset photo = '#TripQuery.photo#'>
<cfset baseCost = #TripQuery.baseCost#>
<cfset numberPeople = #TripQuery.numberPeople#>
<cfif isDefined("TripQuery.depositRequired")>
<cfset depositRequired = 'Yes'>
<cfelse>
<cfset depositRequired = 'No'>
</cfif>
<cfelse>
<cfset tripName = ''>
is passed on the URL, the tripedit.cfm page must query the database and
block that appears at the top of
cfquery

Exercise 6: Inserting values in the edit form

139

Advertisement

Table of Contents
loading

This manual is also suitable for:

Colfusion mx 7 - installing and using coldfusion mx

Table of Contents