O'Reilly logo

Programming ColdFusion MX, 2nd Edition by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required