Exercise 3: Enabling searching from the Trip Detail page

You already created a search capability when you created the tripsearchform.cfm page in Lesson 4: Building Dynamic Queries. 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.

Reviewing the code

The following table describes the code that executes when the user clicks the Search button:

Code

Explanation

<cfif IsDefined("Form.btnSearch")>
	<cflocation url="tripsearchform.cfm">

If the Form.btnSearch variable exists because the user clicked the Search button, go to the page tripsearchform.cfm.