CFINPUT

CFINPUT is used inside CFFORM to place radio buttons, checkboxes, or text boxes. Provides input validation for the specified control type.

CFINPUT supports the JavaScript onClick event in the same manner as the HTML INPUT tag:

<CFINPUT TYPE="radio"
    NAME="radio1"
    onClick="JavaScript_function">

Syntax

<CFINPUT TYPE="input_type"
    NAME="name"
    VALUE="initial_value"
    REQUIRED="Yes/No"
    RANGE="min_value, max_value"
    VALIDATE="data_type"
    ONVALIDATE="javascript_function"
    MESSAGE="validation_msg"
    ONERROR="text"
    SIZE="integer"
    MAXLENGTH="integer"
    CHECKED="Yes/No"            
    PASSTHROUGH="HTML_attributes"            >

TYPE

Optional. Valid entries are:

NAME

Required. A name for the form input element.

VALUE

Optional. An initial value for the form input element.

REQUIRED

Optional. Enter Yes or No. Default is No.

RANGE

Optional. Enter a minimum value, maximum value range separated by a comma. Valid only for numeric data.

VALIDATE

Optional. Valid entries are:

ONVALIDATE

Optional. The name of a valid JavaScript function used to validate user input. The form object, input object, and input object value are passed to the specified routine, which should return true if validation succeeds and false otherwise. When used, the VALIDATE attribute is ignored.

MESSAGE

Optional. Message text to appear if validation fails.

ONERROR

Optional. The name of a valid JavaScript function you want to execute in the event of a failed validation.

SIZE

Optional. The size of the input control. Ignored if TYPE is Radio or Checkbox.

MAXLENGTH

Optional. The maximum length of text entered when TYPE is Text.

PASSTHROUGH

Optional. HTML attributes that are not explicitly supported by CFINPUT. If you specify an attribute and its value, the attribute and value are passed to the HTML code that is generated for the CFINPUT tag. See the Usage section for more information about specifying values.

Usage

You can add standard and dynamic HTML FORM tag attributes and their values to the CFINPUT tag by using the PASSTHROUGH attribute. These attributes and values are passed directly through ColdFusion to the browser in creating a form.

If you specify a value in quotation marks, you must escape the quotation marks by doubling them, for example,

PASSTHROUGH= "readonly= " "YES " " "

Example

<!--- This example shows the use of CFINPUT to validate input --->
<HTML>
<HEAD>
<TITLE>
CFINPUT Example
</TITLE>
</HEAD>

<BODY bgcolor=silver>
<H3>CFINPUT Example</H3>

<!--- this example shows the use of CFINPUT within a CFFORM to
ensure simple validation of text items --->
<CFFORM ACTION="cfinput.cfm" METHOD="POST" ENABLECAB="Yes">

<!--- phone number validation --->
Phone Number Validation (enter a properly formatted phone number):
<BR><CFINPUT TYPE="Text" NAME="MyPhone" MESSAGE="Please enter telephone
number, formatted xxx-xxx-xxxx (e.g. 617-761-2000)" VALIDATE="telephone"
REQUIRED="Yes"><font size=-1 color=red>Required</FONT>
<!--- zip code validation --->
<P>Zip Code Validation (enter a properly formatted zip code):
<BR><CFINPUT TYPE="Text" NAME="MyZip" MESSAGE="Please enter zip code,
formatted xxxxx or xxxxx-xxxx" VALIDATE="zipcode" REQUIRED="Yes"><font
size=-1 color=red>Required</FONT>
<!--- range validation --->
<P>Range Validation (enter an integer from 1 to 5):
<BR><CFINPUT TYPE="Text" NAME="MyRange" RANGE="1,5" MESSAGE="You must
enter an integer from 1 to 5" VALIDATE="integer" REQUIRED="No">
<!--- date validation --->
<P>Date Validation (enter a properly formatted date):
<BR><CFINPUT TYPE="Text" NAME="MyDate" MESSAGE="Please enter a correctly
formatted date (dd/mm/yy)" VALIDATE="date" REQUIRED="No">

<INPUT TYPE="Submit" NAME="" VALUE="send my information">
</CFFORM>

</BODY>
</HTML>