CFML Reference
|
|
ColdFusion Tags
|
cfinput
Description
Used inside cfform
to place radio buttons, checkboxes, or text boxes. Provides input validation for the specified control type.
Category
Forms tags
Syntax
<cfinput type = "input_type"
name = "name"
value = "initial_value"
required = "Yes" or "No"
range = "min_value, max_value"
validate = "data_type"
onValidate = "javascript_function"
pattern = "regexp"
message = "validation_msg"
onError = "text"
size = "integer"
maxLength = "integer"
checked
passThrough = "HTML_attributes">
See also
cfapplet,
cfform,
cfgrid,
cfselect,
cfslider,
cftextinput,
cftree
Attributes
Attribute |
Description |
type
|
Optional. Valid entries are:
- text (default) Creates a text entry box control.
- radio Creates a radio button control.
- checkbox Creates a checkbox control.
- password Creates a password entry control.
|
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 and maximum value range, separated by a comma. Valid only for numeric data.
|
validate
|
Optional. Valid entries are:
- date Verifies US date entry in the form mm/dd/yyyy.
- eurodate Verifies European date entry in the form dd/mm/yyyy.
- time Verifies a time entry in the form hh:mm:ss.
- float Verifies a floating point entry.
- integer Verifies an integer entry.
- telephone Verifies a telephone entry. Telephone data must be entered as ###-###-####. The hyphen separator (-) can be replaced with a blank. The area code and exchange must begin with a digit between 1 and 9.
- zipcode (U.S. formats only) Number can be a 5-digit or
9-digit zip in the form #####-####. The hyphen separator (-) can be replaced with a blank.
- creditcard Blanks and dashes are stripped and the number is verified using the mod10 algorithm.
- social_security_number Number must be entered as ###-##-####. The hyphen separator (-) can be replaced with a blank.
- regular_expression Matches the input against the regular expression specified by the
pattern attribute. Text that matches the regular expression pattern is valid.
|
onValidate
|
Optional. The name of a 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. If used, the validate attribute is ignored.
|
pattern
|
Optional. The JavaScript regular expression pattern to use to validate the input. Required only if you specify validate = "regular_expression" .
|
message
|
Optional. Message text to appear if validation fails.
|
onError
|
Optional. The name of a 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, if n type is Text.
|
checked
|
Optional. No arguments. Applies if type = "radio" or checkbox . If present in the cfinput tag, causes the radio button or checkbox button to be pre-checked.
|
passThrough
|
Optional. HTML attributes that are not explicitly supported by cfinput . If you specify an attribute and value, they are passed to the HTML code generated for the cfinput tag.
|
Usage
You can add standard and dynamic HTML form
tag attributes and values to the cfinput
tag by using the passThrough
attribute. They are passed 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 " " "
cfinput
supports the JavaScript onClick
event in the same manner as the HTML input
tag:
<cfinput type = "radio"
name = "radio1"
onClick = "JavaScript_function">
Note cfinput requires the client to download a Java applet. Downloading an applet takes time, so using cfinput may be slightly slower than using a simple HTML form. Browsers must be Java-enabled for cfinput to work properly.
|
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>
Copyright © 2001, Macromedia Inc. All rights reserved. |
|