Creating an Update Form  
 
 

An update form is similar to an insert form with two key differences. An update form contains a reference to the primary key of the record that is being updated. A primary key is a field or combination of fields in a database table that uniquely identifies each record in the table. For example, in a table of Employee names and addresses, only the Employee_ID would be unique to each record. Because the purpose of an update form is to update existing data, the contents of an update form are usually populated out of a database.

 
 
  Dynamically populating an update form  
 
 

To populate the fields of an update form, you must first select the record out of the database with a CFQUERY. Then put the form in a CFOUTPUT statement to reference the fields.

 
 
  Designating the primary key  
 
 

The easiest way to designate the primary key in an update form is to include a hidden input field with the value of the primary key for the record you want to update.

 
 
  Example: Primary key value  
 
<!--- Query to select record --->
<CFQUERY NAME="EmployeeRecord"
    DATASOURCE="Employee DB">
    SELECT *
        FROM Employees
        WHERE Employee_ID = #URL.EmployeeID#
</CFQUERY>

<HTML>
<HEAD>
    <TITLE>Input Form</TITLE>
</HEAD>
<BODY>

<CFOUTPUT QUERY="EmployeeRecord">

<!--- Input form --->
<FORM ACTION="EmployeeUpdate.cfm" METHOD="Post">

<!--- Primary Key value indicating record to update --->
<INPUT TYPE="Hidden" NAME="Employee_ID" 
    VALUE="#Employee_ID#">
<PRE>
    FirstName: <INPUT TYPE="Text" NAME="FirstName" 
        VALUE="#FirstName#">
    LastName: <INPUT TYPE="Text" NAME="LastName" 
        VALUE="#LastName#">
    Phone: <INPUT TYPE="Text" NAME="Phone" 
        VALUE="#Phone#"><BR>
    <INPUT TYPE="Submit" VALUE="Update Information">
</PRE>
</FORM>
</CFOUTPUT>

</BODY>
</HTML>

In this example, Employee_ID is the primary key of the Employees table, so a hidden field named Employee_ID is included in the HTML form. The hidden field indicates to ColdFusion which record to update. In this case, the record ID was passed as the URL parameter EmployeeID:

http://web_root/updateform.cfm?employeeid=2


 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.