Passing Data Using Forms

Another method for passing data from template to template involves sending the data via the HTTP Post method as form-field data. When you create an HTML form that posts to another ColdFusion template, each form field is automatically available as a form variable within the template specified in the ACTION attribute of the FORM tag. Within the receiving template, each form field can be referenced by prefixing the field name with Form, as in Form. MyField. To see just how this works, let’s look at an example. The ContactForm.cfm template, shown in Example 3-6, creates a simple HTML form that collects basic contact information and posts it to the DisplayContactInfo.cfm template, shown in Example 3-7.

Example 3-6. Template for Collecting and Posting Contact Information

<HTML> <HEAD> <TITLE>Passing Variables via Form Fields</TITLE> </HEAD> <BODY> <H2>Employee Contact Information</H2> <FORM ACTION="DisplayContactInfo.cfm" METHOD="post"> <TABLE> <TR> <TD>Name:</TD> <TD><INPUT TYPE="text" NAME="Name" SIZE="25" MAXLENGTH="50"></TD> </TR> <TR> <TD>Title:</TD> <TD><INPUT TYPE="text" NAME="Title" SIZE="25" MAXLENGTH="50"></TD> </TR> <TR> <TD>Department:</TD> <TD><INPUT TYPE="text" NAME="Department" SIZE="25" MAXLENGTH="50"></TD> </TR> <TR> <TD>E-mail:</TD> <TD><INPUT TYPE="text" NAME="Email" SIZE="25" MAXLENGTH="255"></TD> </TR> <TR> <TD>Phone Ext.:</TD> <TD><INPUT TYPE="text" NAME="PhoneExt" SIZE="6" MAXLENGTH="4"></TD> </TR> <TR> <TD COLSPAN="2"><INPUT TYPE="submit" ...

Get Programming ColdFusion now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.