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> ...
Get Programming ColdFusion now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.