Exercise 2: Adding database maintenance buttons

The search and sequential navigation capabilities are features for locating Compass Travel trips. After locating a trip, the trip coordinator must be able to modify or delete it. Additionally, when viewing the detail for a trip, the trip coordinator must be allowed to add a new trip or use the search facility. To enable trip coordinators to do this, you add the following buttons to the Trip Detail page:


This image shows a picture of the maintenance buttons.

As described in Exercise 1: Creating the main application page from the Trip Detail page, it is important to pass the current record ID (tripID) to the action page to build the proper SQL statement to process the navigation button requests. It is also important to pass the current record ID to the Maintenance Action page. Therefore, you use an HTML input tag to hide the current recordID and post it to the maintenanceaction.cfm page.

To add maintenance buttons:

  1. Open the tripdetail.cfm file from the my_app subdirectory.
  2. Enter the following code immediately after the <cfoutput query="TripQuery"> tag:
    <form action="maintenanceaction.cfm" method="post">
    	<input type="hidden" name="RecordID" value="#tripID#">
    	<input type="submit" name="btnAdd" value="   Add    ">
    	<input type="submit" name="btnEdit" value="  Edit  ">
    	<input type="submit" name="btnDelete" value="Delete">
    	<input type="submit" name="btnSearch" value="Search">
    </form>
    

    Note: The current trip record ID (tripID) is in a hidden field in the form code. This field provides the action page with current record ID that it must have in order to build the query to access the appropriate record in the Trips database table.

  3. Save the file.

To test the updated application:

  1. Open your browser.
  2. Enter the following URL to view the updated tripdetail.cfm page
    http://localhost/cfdocs/getting_started/my_app/tripdetail.cfm?ID=8
    

    Note: If you are using the built-in ColdFusion server, enter localhost:8500 instead of localhost.

    The page appears as follows:


    This image shows a picture of the Trip Maintenance page with maintenance buttons.

  3. Click Search or Delete to test the database maintenance buttons.

    An error occurs because the Maintenance Action page does not exist. The Maintenance Action page is required to process the maintenance button requests. You will develop this page in Lesson 7: Validating Data to Enforce Business Rules.