Exercise 2: Creating a simple action page

In this exercise, you develop an action page that you will eventually use to insert or update trip data passed from the Trip Edit page into the trips table of the Compass Travel database.

To build the Trip Edit action page:

  1. Create a blank file.
  2. Enter or copy and paste the following code into the file:
    <html>
    	<head>
    		<title>Trip Maintenance Confirmation</title>
    	</head>
    	<body>
    			<h1>Trip Added</h1>
    			<!--- Database insert logic goes here. --->
    			<cfoutput>
    				You have added #Form.TripName# to the trips database.
    			</cfoutput>
    	</body>
    </html>
    
  3. Save the page as tripeditaction.cfm in the my_app directory.

To test the trip edit page:

  1. Open the tripedit.cfm page in the my_app directory in a browser.
  2. In the Trip Name field, enter 12345.
  3. Click Save.

    The message "You have added 12345 to the trips database." appears. The tripeditaction.cfm page does not actually update the database yet; it simply displays a message saying that you added the trip to the database. Before you add the code to allow updates to the database, you must add the logic to validate the data entered in the form.

Reviewing the code

The following table describes the code that you use to verify whether a file exists:

Code

Explanation

	<h1>Trip Added</h1>
	<!--- Database insert logic goes here. --->
	<cfoutput>You have added #Form.TripName# to the trips database.
	</cfoutput>

Displays the heading "Trip Added." Displays the message "You have added TripName to the trips database," where TripName is the trip name you entered in the form’s Trip Name field.