LISTING 1: FORMS1.CFM ­ HTML Forms Can Be Used to Collect and Submit Data to ColdFusion for Processing

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 1</TITLE>
</HEAD>

<BODY>

<FORM ACTION="forms2.cfm" METHOD="POST">

Please enter your name and then click <B>Process</B>.
<P>
First name:
<INPUT TYPE="text" NAME="FirstName">
<BR>
Last name:
<INPUT TYPE="text" NAME="LastName">
<BR>
<INPUT TYPE="submit" VALUE="Process">

</FORM>

</BODY>

</HTML>
 

LISTING 2: FORMS2.CFM ­ Processing Form Fields

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 2</TITLE>
</HEAD>

<BODY>

<CFOUTPUT>

Hello #FirstName# #LastName#

</CFOUTPUT>

</BODY>

</HTML>
 

LISTING 3: FORMS3.CFM ­ Using Option Buttons and Check Boxes

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 3</TITLE>
</HEAD>

<BODY>

<FORM ACTION="forms4.cfm" METHOD="POST">

Please fill in this form and then click <B>Process</B>.
<P>
Payment type:<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="Cash">Cash<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="Check">Check<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="Credit card">Credit card<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="P.O.">P.O.
<P>
Would you like to be added to our mailing list?
<INPUT TYPE="checkbox" NAME="MailingList" VALUE="Yes">
<P>
<INPUT TYPE="submit" VALUE="Process">

</FORM>

</BODY>

</HTML>

LISTING 4: FORMS4.CFM ­ Processing Option Buttons and Check Boxes

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 4</TITLE>
 

</HEAD>

<BODY>

<CFOUTPUT>

Hello,<BR>
You selected <B># PaymentType#</B> as your payment type.<BR>
<CFIF #MailingList# IS "Yes">
You will be added to our mailing list.
<CFELSE>
You will not be added to our mailing list.
</CFIF>
</CFOUTPUT>

</BODY>

</HTML>
 

LISTING 5: FORMS5.CFM ­ Using Hidden Fields to Set Default Form Values

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 5</TITLE>
</HEAD>

<BODY>

<FORM ACTION="forms4.cfm" METHOD="POST">

Please fill in this form and then click <B>Process</B>.
<P>
Payment type:<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="Cash" CHECKED>Cash<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="Check">Check<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="Credit card">Credit card<BR>
<INPUT TYPE="radio" NAME="PaymentType" VALUE="P.O.">P.O.
<P>
Would you like to be added to our mailing list?
<INPUT TYPE="checkbox" NAME="MailingList" VALUE="Yes">
<P>
<INPUT TYPE="submit" VALUE="Process">

</FORM>

</BODY>

</HTML>

LISTING 6: FORMS6.CFM ­ Using a SELECT List Box for User Options

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 6</TITLE>
</HEAD>

<BODY>

<FORM ACTION="forms4.cfm" METHOD="POST">

Please fill in this form and then click <B>Process</B>.
<P>
Payment type:
<SELECT NAME="PaymentType">
<OPTION>Cash
<OPTION>Check
<OPTION>Credit card
<OPTION>P.O.
</SELECT>
<P>
Would you like to be added to our mailing list?
<INPUT TYPE="checkbox" NAME="MailingList" VALUE="Yes">
<P>
<INPUT TYPE="submit" VALUE="Process">

</FORM>

</BODY>

</HTML>
 

LISTING 7: FORMS7.CFM ­ Using a Text Area Field

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 7</TITLE>
</HEAD>

<BODY>

<FORM ACTION="forms8.cfm" METHOD="POST">

Please enter your comments in the box provided, and then click <B>Send</B>.
<P>
<TEXTAREA NAME="Comments" ROWS="6" COLS="40"></TEXTAREA>
<P>
<INPUT TYPE="submit" VALUE="Send">

</FORM>

</BODY>

</HTML>

LISTING 8: FORMS8.CFM ­ Processing Free-Form Text Area Fields

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 8</TITLE>
</HEAD>

<BODY>

<CFOUTPUT>

Thank you for your comments. You entered:

<P>

<B>#FORM.Comments#</B>

</CFOUTPUT>

</BODY>

</HTML>
 

LISTING 9: FORMS9.CFM ­ The HTML TEXTAREA Field with Wrapping Enabled

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 9</TITLE>
</HEAD>

<BODY>

<FORM ACTION="forms10.cfm" METHOD="POST">

Please enter your comments in the box provided, and then click <B>Send</B>.
<P>
<TEXTAREA NAME="Comments" ROWS="6" COLS="40" WRAP="VIRTUAL">
Replace this text with your comments.
</TEXTAREA>
<P>
<INPUT TYPE="submit" VALUE="Send">

</FORM>

</BODY>

</HTML>

LISTING 10: FORMS10.CFM ­ Using the ParagraphFormat Function to Preserve Line Breaks

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 10</TITLE>
</HEAD>

<BODY>

<CFOUTPUT>

Thank you for your comments. You entered:

<P>

<B>#ParagraphFormat(FORM.Comments)#</B>

</CFOUTPUT>
 

</BODY>

</HTML>
 

LISTING 11 ­ FORMS12.CFM ­ Template with a Reset Button and Multiple Submit Buttons

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 11</TITLE>
</HEAD>

<BODY>

<FORM ACTION="forms12.cfm" METHOD="POST">

<P>

First name:
<INPUT TYPE="text" NAME="FirstName">
<BR>
Last name:
<INPUT TYPE="text" NAME="LastName">

<P>
<INPUT TYPE="submit" NAME="Operation" VALUE="Update">
<INPUT TYPE="submit" NAME="Operation" VALUE="Delete">
<INPUT TYPE="reset" VALUE="Clear">

</FORM>

</BODY>

</HTML>

Listing 12: FORMS12.CFM ­ ColdFusion Example of Multiple Submit
Button Processing

<HTML>

<HEAD>
<TITLE>Learning ColdFusion Forms 12</TITLE>
</HEAD>

<BODY>

<CFOUTPUT>

<CFIF FORM.Operation IS "Update">
You opted to <B>update</B> #FirstName# #LastName#
<CFELSEIF FORM.Operation IS "Delete">
You opted to <B>delete</B> #FirstName# #LastName#
</CFIF>

</CFOUTPUT>

</BODY>

</HTML>