![]() ![]() ![]() |
When creating a form in HTML, recall that you must specify the ACTION and METHOD attributes. Generally, the METHOD attribute is "POST" and the ACTION attribute specifies the name of the ColdFusion page (.CFM) file you want to execute.
The ACTION attribute in an HTML form tells the browser what to do when the user clicks the Submit button. In the following example, the insdata.cfm
page is executed when the user submits the form data for processing.
<FORM ACTION="insdata.cfm" METHOD="Post">
Creating data entry fields for an HTML form is very simple: you need only create the HTML form fields for each database field into which you want to insert data. The names of your form fields must be identical to the names of your database fields.
For example, if you have a table called Employees with three fields called FirstName, LastName, and Phone, your form fields might look like this:
First Name: <INPUT TYPE="text" NAME="FirstName"> Last Name: <INPUT TYPE="text" NAME="LastName"> Phone: <INPUT TYPE="text" NAME="Phone">
You can use the full range of HTML input controls, including list boxes, radio buttons, checkboxes, and multi-line text boxes in your forms. When ColdFusion reads the contents of the form submittal, it uses the NAME attribute to map HTML form fields to the corresponding database fields and inserts the data entered by the user into the appropriate database fields.
Hidden fields are a special type of form input field. When you define a hidden input field, the field remains a part of the HTML form but is not displayed to the user. When a user submits the form, the VALUE of the hidden field (which is typically specified when preparing the form) is sent to ColdFusion along with user-entered fields that are not hidden.
For example, if you want a form submitted by a user to always include the site from which it was submitted, you might have a hidden input field such as:
<INPUT TYPE="Hidden" NAME="SiteName" VALUE="CompanyName">
In the above case, every time a user completes the HTML form, a variable with the name "SiteName" and the value "CompanyName" is passed as a part of the form submittal.
The following example demonstrates a simple HTML form:
<FORM ACTION="insdata.cfm" METHOD="Post"> <!-- Data entry fields --> <PRE> First Name: <INPUT TYPE="text" NAME="FirstName"> Last Name: <INPUT TYPE="text" NAME="LastName"> Phone: <INPUT TYPE="text" NAME="Phone"> <INPUT TYPE="Submit" VALUE="Enter Information"> </PRE> </FORM>
The form has three inputs: FirstName, LastName, and Phone. The user can enter data in these text areas and click the Submit button. When the Submit button is clicked, the form action is carried out, and all inputs (including hidden inputs) are made available to the next page.
Suppose the user enters his first name as "William," his last name as "Gibson," and his phone as "(212)323-9734." When he clicks the Submit button, the form variables shown below are sent to the page:
FirstName=William LastName=Gibson Phone=(212)323-9734
This page might display these variables, insert them into the database, or perhaps do both depending on your application.
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.