Macromedia colfusion mx 7-getting started building coldfusion mx applications User Manual

Page of 152
Exercise 3: Enabling searching from the Trip Detail page
127
Exercise 2: Determining actions based on which button a 
user clicks
In 
, you added buttons to the Trip 
Detail page to let users search and modify the trips database; however, because you had not yet 
written the code to implement these capabilities, ColdFusion displayed an error when you clicked 
the buttons. Clicking these button sends the user to the maintenanceaction.cfm page. In this 
exercise, you will create the Maintenance Action page (maintenanceaction.cfm).
ColdFusion creates a variable only for the button that the user clicked. You use the 
IsDefined
 
function to test for the existence of the variable, which determines which action the application 
takes.
To create the Maintenance Action page:
1.
Create a blank file.
2.
Enter the following code in the blank file:
<cfif IsDefined("Form.btnSearch")>
<!--- Code to execute if the user clicked Search. --->
<cfelseif IsDefined("Form.btnDelete")>
<!--- Code to execute if the user clicked Delete. --->
<cfelseif IsDefined("Form.btnEdit")>
<!--- Code to execute if the user clicked Edit. --->
<cfelseif IsDefined("Form.btnAdd")>
<!--- Code to execute if the user clicked Add. --->
</cfif>
3.
Save the file as maintenanceaction.cfm in the my_app directory.
Exercise 3: Enabling searching from the Trip Detail page
You already created a search capability when you created the tripsearchform.cfm page in 
. When the user clicks the Search button, you want to 
navigate to the tripsearchform.cfm page. You use the 
cflocation
 tag to do so.
To enable searching from the Trip Detail page:
1.
Open the maintenanceaction.cfm file in the my_app directory in your editor.
2.
Add the highlighted code in the file.
<cfif IsDefined("Form.btnSearch")>
<!--- Code to execute if the user clicked Search. --->
<cflocation url="tripsearchform.cfm">
<cfelseif IsDefined("Form.btnDelete")>
<!--- Code to execute if the user clicked Delete. --->
<cfelseif IsDefined("Form.btnEdit")>
<!--- Code to execute if the user clicked Edit. --->
<cfelseif IsDefined("Form.btnAdd")>
<!--- Code to execute if the user clicked Add. --->
</cfif>
3.
Save the file.