HTML forms begin with an opening FORM tag and end with a closing FORM tag. The FORM tag accepts two major attributes that you will use to describe the form's associated action page and how to submit values to it.
Within the form block, you'll describe the form controls needed to gather and submit user input.
![]() |
Note: | Because forms are not ColdFusion-specific, the syntax and examples that follow provide you with just enough detail to get going with ColdFusion Express. |
<FORM ACTION="ActionPage" METHOD="Post"> ... </FORM>
All ColdFusion forms must be submitted with an attribute setting of METHOD="Post".
There are a variety of form controls types available. You choose form control input types based on the type of input the user should provide. For example:
This code creates a text contol:
<INPUT TYPE="Text" NAME="ControlName" SIZE="Value" MAXLENGTH="Value">
This code creates a series of radio buttons:
<INPUT TYPE="RadioButton" NAME="ControlName" VALUE="Value1">DisplayName1 <INPUT TYPE="RadioButton" NAME="ControlName" VALUE="Value2">DisplayName2 <INPUT TYPE="RadioButton" NAME="ControlName" VALUE="Value3">DisplayName3
This code creates a drop down select box:
<SELECT NAME="ControlName"> <OPTION VALUE="Value1 ">DisplayName1 <OPTION VALUE="Value2">DisplayName2 <OPTION VALUE="Value3">DisplayName3 </SELECT>
This code creates a check box:
<INPUT TYPE="Checkbox" NAME="ControlName" VALUE="Yes|No">Yes
This code creates a reset button:
<INPUT TYPE="Reset" NAME="ControlName" VALUE="DisplayName">
This code creates a submit button:
<INPUT TYPE="Submit" NAME="ControlName" VALUE="DisplayName">
Click here to see form controls in action.
The code below creates a form for users to enter employee information. The comments explain the code in this context.
<HTML> <HEAD> <TITLE>Input form</TITLE> </HEAD> <BODY> <!--- define the action page in the form tag. The form variables will pass to this page when the form is submitted ---> <FORM ACTION="ActionPage.cfm" METHOD="POST"> <!--- title the form---> <H4>Employee Data Form</H4> <!--- use P tags to format your form---> <P> <!--- text field label---> Employee Last Name<BR> <!--- text field allows users to enter an employee's last name---> <INPUT TYPE="Text" NAME="LastName" size="20" maxlength="50"> </P> <P> <!--- drop down select box allows users to select a department ---> <!--- label the form control---> Department<BR> <SELECT NAME="Department"> <OPTION VALUE="Training">Training</OPTION> <OPTION VALUE="Marketing">Marketing</OPTION> <OPTION VALUE="HR">HR</OPTION> <OPTION VALUE="Sales">Sales</OPTION> </SELECT> </P> <P> <!--- checkbox allows users to identify contract employees ---> <!--- label the field---> Contract Employee?<BR> <INPUT TYPE="Checkbox" NAME="Contract" VALUE="Yes">Yes </P> <P> <!--- the submit button passes data to the action page specified in the opening form tag---> <INPUT TYPE="Submit" NAME="SubmitButton" VALUE="Submit Form"> </P> <P> <!--- reset button resets the data on the form ---> <INPUT TYPE="Reset" NAME="Reset" VALUE="Reset Form Values"> </P> <!--- end form ---> </FORM> </BODY> </HTML>
![]() |
To create a form to accept user input: |
FormPage.CFM
within the CFDOCS
directory. Remember that CFDOCS
resides under your web root directory.
<FORM ACTION = "ActionPage.cfm" METHOD = "POST">
<H4>Employee Data Form </H4>
<INPUT TYPE = "Text" NAME = "LastName" SIZE = "20" MAXLENGTH = "50">
Last Name <BR>
<SELECT NAME = "Department"> <OPTION VALUE = "Training">Training</OPTION> <OPTION VALUE = "Marketing">Marketing</OPTION> <OPTION VALUE = "HR">HR</OPTION> <OPTION VALUE = "Sales">Sales</OPTION> </SELECT>
Department<BR>
<INPUT TYPE="Checkbox" NAME="Contract" VALUE="Yes">Yes
Contract employee?<BR>
<INPUT TYPE="Submit" NAME="SubmitButton" VALUE="Submit Form">
<INPUT TYPE="Reset" NAME="ResetButton" VALUE="Reset Form Values">
</FORM>
The form appears in the browser.
Remember that you need an action page in order to submit values; you will create one later in this chapter.
Click here to see how the page should look at this time.
Click here to see the code behind the scenes.
![]() |
Note: | You will receive errors if you submit the form for processing at this time. You will learn about action pages and the characteristics of form variables later on in this chapter. |