Exercise 2: Determining actions based on which button a user clicks

In Lesson 6: Creating a Main Application Page, 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.