View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfinput PreviousNext

cfinput

Used within the cfform tag, to place radio buttons, check boxes, or text boxes on a form. Provides input validation for the specified control type.

Forms tags

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

cfapplet, cfform, cfgrid, cfselect, cfslider, cftextinput, cftree

ColdFusion MX 6.1: Changed the requirements for the validate = "creditcard" option: it requires that the text entry have 13-16 digits.

ColdFusion MX: Changed the cfform tag preserveData attribute behavior: if it is set to True, ColdFusion checks radio and check box values only if their value matches the posted value for the control. (In earlier releases, if the posted value did not match any of the cfinput check boxes or radio buttons for the control, the checked attribute was used.

Attribute

Req/Opt

Default

Description

type

Optional

text

  • text: creates a text entry box control
  • radio: creates a radio button control
  • checkbox: creates a check box control
  • password: creates a password entry control

name

Required

 

Name for form input element.

value

Optional

 

Initial value for form input element.

required

Optional

No

  • Yes
  • No

range

Optional

 

Minimum and maximum value range, separated by a comma. If type = "text" or "password", this applies only to numeric data.

validate

Optional

 

Verifies a value's format:

  • date: US date mm/dd/yyyy
  • eurodate: European date dd/mm/yyyy
  • time: time hh:mm:ss
  • float: floating point entry
  • integer: integer entry
  • telephone: telephone ###-###-####. Separator: hyphen or blank. Area code and exchange must begin with a digit 1 - 9.
  • zipcode: (U.S. formats only) 5-digit ##### or 9-digit #####-####. Separator: hyphen or blank.
  • creditcard: must be a 13 to 16 digit integer after stripping blanks and dashes; uses the mod10 algorithm.
  • social_security_number: ###-##-####. Separator: hyphen or blank.
  • regular_expression: matches input against regular expression specified by the pattern attribute.

onValidate

Optional

 

Custom JavaScript function to validate user input. The form object, input object, and input object values are passed to the routine, which should return True if validation succeeds, and False otherwise. If used, the validate attribute is ignored.

pattern

Required if validate = "regular_
expression"

 

JavaScript regular expression pattern to validate input. Omit leading and trailing slashes. For examples and syntax, see Building Dynamic Forms in Developing ColdFusion MX Applications.

message

Optional

 

Message text to display if validation fails.

onError

Optional

 

Custom JavaScript function to execute if validation fails.

size

Optional

 

Size of input control. Ignored, if type = "radio" or "checkbox".

maxLength

Optional

 

Maximum length of text entered, if type = "Text" or "password".

checked

Optional

 

Selects a control. No value is required.

Applies if type = "radio" or "checkbox".

Optional: you can enter the following values:

  • true (equivalent to checked)
  • false (equivalent to omitting the attribute)

passThrough

Optional

 

Passes one or more arbitrary attribute-value pairs to the HTML code that is generated for the tag. You can use either of the following formats to include the quotation marks around the attribute value:

passthrough="ID=""myID"""
passthrough='ID="myID"'

The second format, which surrounds all the attribute-value pairs to be passed through in single quotation marks is clearer, particularly when you pass multiple HTML attributes.

<em>

In addition to the listed attributes, you can use the following HTML attributes in the cfform tag without using the passThrough attribute. The tag does not use these attributes, but includes them in the HTML of the form tag that it generates and returns to the browser:

If the cfform preserveData attribute is true and the form posts back to the same page, the posted value of the cfinput control is used, instead of its Value or Checked attribute.

If cfinput check box or radio type values match the submitted value for the control, ColdFusion checks their values. If no value matches, nothing is checked.

To add other HTML <input> tag attributes and values to this tag, use the passThrough attribute. They are passed through ColdFusion to the browser when creating a form. The supported HTML attributes are: CLASS, ID, MAXLENGTH, MESSAGE, ONBLUR, ONCHANGE, ONCLICK, ONDBLCLICK, ONFOCUS, SIZE, STYLE, and TABINDEX.

If you specify a value in quotation marks, you must escape them; for example,

passThrough = "readonly = " "YES " " "

For more information, see cfform. For information on using JavaScript regular expressions with this tag, see Building Dynamic Forms in Developing ColdFusion MX Applications.

<!--- this example shows the use of cfinput within a cfform to ensure simple
validation of text items ---> <cfform action = "cfinput.cfm"> <!--- phone number validation ---> Phone Number Validation (enter a properly formatted phone number): <br> <cfinput type = "Text" name = "MyPhone" message = "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 = "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 = "Enter a correctly formatted date (dd/mm/yy)" validate = "date" required = "No"> <input type = "Submit" name = "" value = "send my information"> </cfform>

Contents > CFML Reference > ColdFusion Tags > cfinput PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


No screen name said on Aug 25, 2004 at 4:19 AM :
The onValidate parameter of CFInput (type=TEXT) seems to be ignored by the CF server if any of the fields on the CFForm have required set to YES
lbdas357 said on Nov 11, 2004 at 12:13 PM :
If we use the <CFINPUT Time validation how can we determine AM or PM?
Adam Cameron said on Dec 27, 2004 at 7:14 PM :
It'd be quite nice if these docs had a summary of JavaScript's regex patterns, rather than just telling us <cfinput> uses them (which in itself is not very helpful).
To save anyone time having to seek a reference out, I use this one (it's Microsoft, so strictly speaking JScript not JavaScript, but I've never come across an incompatibility yet):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsgrpregexpsyntax.asp
wooddog said on Jan 26, 2005 at 8:17 AM :
There is a problem with the validate integer when using the cfinput='text'. It excepts .5 as an integer or any whole number with a decimal in front of it.
No screen name said on Jun 3, 2005 at 7:04 AM :
HTML attribute disabled would be useful to be added in next versions
jrunrandy said on Jun 29, 2005 at 12:59 PM :
I believe that cfinput supports a disabled attribute in CFMX 7: http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000279.htm
lizk said on Jul 13, 2005 at 4:26 AM :
i have this tag in the form
<CFINPUT TYPE="text" name="DirPHoneNo"
value="#form.DirPHoneNo#" label="Project Director Telephone number Input Box" mask="999-999-9999" validateAt="onBlur" validate="telephone" required="yes" message="enter valid phone number">
onBlur is ignored if i enter only part of the phone number (2 digits insted of 10). Can't submit form- no error message, no validation message- just wouldn't submit. I have js page included as well. tried removing js page reference- no luck. Also tried different masking.
Another problem: when using mask, if enter some digits but not all, remaining spaces are replaced by 0's instead of throwing error
y_not_25 said on Aug 9, 2005 at 2:14 AM :
HTML attributes class and id would be useful to be added in next versions.

I use id to assign a Label to a check- or radio-box like:
<input type="checkbox" name="lorem" id="lorem_1" value="1" /><label for="lorem_1">Lorem</label>
(more comfotable would of course be a label-attribute in the cfinput, which generates an id and label tag... ;-) )

Here's a workaround for the class attribute, but the class-attribute would be nicer:
<span class="yourStyle"><cfinput [...] /></span>
define the style in the css like this:
yourStyle input
{
/* ...*/
}

thx
Devline said on Oct 9, 2005 at 2:58 PM :
cfinput supports a disabled attribute in CFMX 7, but it ignores the argument "no"
hpottash said on Apr 4, 2006 at 7:46 AM :
The documentation for onValidate could probably use an example... so here is one. If you give it something other than exactly what it is exspecting you get very odd behaviour across your whole form.

<head>
<script>
function validateCheese(formObj,InputObj,InputObjVal){
return (inputObj.value == "cheese");
}
</script>
</head>
<body>
<cfinput
type = "Text" name = "cheese"
message = "you did not entere cheese"
onValidate = "validateCheese" >
</body>

Note that the javascript function name is passed to onvalidate, but that it is not called as a function (there are no tailing parens). also note that the function definition requires three paramiters (this is important) and that it always returns a booliean value. Even if you don't want to use any of the params passed to the function you need to take them.
Glizman said on Jun 12, 2006 at 6:43 AM :
In response to hpottash and onValidate, I appreciate the example code. I experimented with it and see what might be causing the "strange form behavior". Javascript is case-sensitive. The second input parameter is not matched exactly in case in the return statement. By capitalizing the "i" in "inputObj.value", I got the function results to be consistent with the input field's value "cheese" onSubmit. Which reminds me, I had to add a submit button! The Javascript failing could be the reason for the other form oddities.

HTH
No screen name said on Dec 11, 2006 at 12:37 PM :
Some additional hints on Validate (which would've helped me to not have to figure out myself):

If you include a Validate attribute, the Message attribute will determine what is displayed if the error condition is met.

The Validate attribute should only include the function name, without parentheses, so a tag might be cfinput type="Text" name="PasswordConfirm" required="No" size="10" onvalidate="passwordsMustMatch" message="Passwords must match."

The function should return true or false, true if there's not an error, false if there is.
halL said on Dec 11, 2006 at 1:16 PM :
In the previous comment on the Validate attribute, the second paragraph refers to the onValidate attribute, not the validate attribute.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p65.htm