O'Reilly logo

Programming ColdFusion 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

Basic Input Controls

The CFINPUT tag closely resembles the HTML INPUT tag and can be used for creating text boxes, password entry boxes, radio buttons, and checkboxes. At the most basic level, the CFINPUT tag behaves exactly like the HTML INPUT tag. Consider the following HTML INPUT tags:

<INPUT TYPE="Text" NAME="MyText" SIZE="10" MAXLENGTH="10" VALUE="MyValue">
<INPUT TYPE="Password" NAME="MyPassword" SIZE="10" MAXLENGTH="10">
<INPUT TYPE="Radio" NAME="MyRadioButton" VALUE="MyValue" CHECKED>
<INPUT TYPE="Checkbox" NAME="MyCheckbox" VALUE="MyValue" CHECKED>

Here are the equivalent CFINPUT tags:

<CFINPUT TYPE="Text" NAME="MyText" SIZE="10" MAXLENGTH="10" VALUE="MyValue">
<CFINPUT TYPE="Password" NAME="MyPassword" SIZE="10" MAXLENGTH="10">
<CFINPUT TYPE="Radio" NAME="MyRadioButton" VALUE="MyValue" CHECKED>
<CFINPUT TYPE="Checkbox" NAME="MyCheckbox" VALUE="MyValue" CHECKED>

As you can see, the tags are virtually identical. What sets a CFINPUT tag apart from its HTML counterpart is built-in data validation. The CFINPUT tag can require input for a given form field as well as validate the data against a predefined or custom validation routine. Example 10-2 demonstrates how to use the CFINPUT tag to require data entry for various input types.

Example 10-2. Creating a Form with CFFORM and CFINPUT

<CFIF ISDEFINED('FORM.FIELDNAMES')> <H3>You submitted:</H3> <CFLOOP INDEX="Field" LIST="#Form.Fieldnames#"> <CFOUTPUT><B>#Field#</B>: #Evaluate(Field)#<BR></CFOUTPUT> </CFLOOP> <HR NOSHADE> </CFIF> ...

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