"> | Tutorial | Webucator"> ">

<cfform> Basics

Contact Us or call 1-877-932-8228
<cfform> Basics

<cfform> Basics

The <cfform> tag is used to generate HTML forms. ColdFusion form controls, such as <cfinput>, <cfselect>, and <cftextarea> are used inside of <cfform> to create HTML entry fields. The table below shows <cfform>'s attributes for HTML forms.

Major <cfform> Attributes for HTML Forms
Attribute Description
name form name
action form action
method form method: "post" or "get"
format "html" for HTML forms

Code Sample:

  <title>Running Log</title>

<cfform name="RunningForm" method="post" action="AddEntry-cfform.cfm" format="html">
	<td><cfinput type="text" name="date" size="20"></td>
	<td><cfinput type="text" name="distance" size="20"></td>
	<td><cfinput type="text" name="time" size="20"></td>
	<td><cftextarea rows="3" cols="40" name="comments"></cftextarea></td>
	<td colspan="2" align="right">
		<cfinput type="submit" name="Add Entry" value="Add Entry">


The generated HTML form code is shown below:

<form name="RunningForm" action="AddEntry-cfform.cfm" method="post" onsubmit="return _CF_checkRunningForm(this)"> <table> <tr> <td>Date:</td> <td><input name="date" id="date" type="text" size="20"/></td> </tr> <tr> <td>Distance:</td> <td><input name="distance" id="distance" type="text" size="20"/></td> </tr> <tr> <td>Time:</td> <td><input name="time" id="time" type="text" size="20"/></td> </tr> <tr> <td>Comments:</td> <td><textarea name="comments" rows="3" cols="40" ></textarea></td> </tr> <tr> <td colspan="2" align="right"> <input name="Add Entry" id="Add Entry" type="submit"/> </td> </tr> </table> </form>

As you can see, it is a basic HTML form with nothing too special about it. However, ColdFusion form tags can do some pretty neat things with the right attributes. In this lesson, we'll learn how to use them to validate forms.