View comments | RSS feed

cfform

Description

Builds a form with CFML custom control tags; these provide more functionality than standard HTML form input elements.

Category

Forms tags

Syntax

<cfform 
  name = "name"
  action = "form_action"
  preserveData = "Yes" or "No"
  onSubmit = "javascript" 
  target = "window_name"
  encType = "type"
  passThrough = "HTML_attribute(s)"
  codeBase = "URL"
  archive = "URL" 
  scriptSrc = "path">
...
</cfform>

See also

cfapplet, cfgrid, cfinput, cfselect, cfslider, cftextinput, cftree, cftreeitem

History

New in ColdFusion MX: the enableCAB attribute is deprecated. Do not use it in new applications. It might not work, and might cause an error, in later releases.

New in ColdFusion MX: the name and action attributes are optional.

Attributes

Attribute Req/Opt Default Description
name
Optional
CFForm_1
[, ...]
A name for the form.
action
Optional

Name of ColdFusion page to execute when the form is submitted for processing.
scriptSrc
Optional
/cfide/scripts/cfform.js
Lets the user control the URL of the script file; useful if you do not keep the file in the /cfide directory.
preserveData
Optional
No
When the cfform action attribute posts back to the same page as the form, this determines whether to override the control values with the submitted values.
  • false: values specified in the control tag attributes are used
  • true: corresponding submitted values are used
Applies to these controls:
  • cfform controls cfinput, cfslider, cftextinput; overrides value attribute value
  • cfselect controls that are populated from queries. Overrides the selected attribute. See cfselect.
  • cftree controls: Overrides the cftreeitem expand attribute. If true, expands previously-selected elements. The cftree completePath attribute must be set to Yes.
  • cfgrid controls: has no effect. (This avoids confusion as to whether data has been resubmitted to the database by the control.)
onSubmit
Optional

JavaScript function to execute after input validation. Use to for preprocessing data before form is submitted. See Developing ColdFusion MX Applications with CFML.
passThrough
Optional

For HTML attributes that are not supported by cfform. Attributes and values are passed to the HTML code that is generated for the tag.
For example:
"style=""font-weight:bold;"""
codeBase
Optional
See Description
URL of downloadable JRE plug-in (for Internet Explorer only).
Default: /CFIDE/classes/cf-j2re-win.cab
archive
Optional
See Description
URL of downloadable Java classes for ColdFusion controls.
Default: /CFIDE/classes/CFJava2.jar

Usage

This tag requires an end tag.

Some custom control tags that you can use within this tag require the client to download a Java applet; they might execute slightly more slowly than using an HTML form element to get the same information. In addition to regular HTML form elements, you can use the following custom control tags within the cfform tag:

All of these control tags require that the browser is JavaScript-enabled.

If you use this tag after the cfflush tag on a page, an error is thrown.

The method attribute is automatically set to post; if you specify a value, it is ignored.

If you specify a value in quotation marks, you must escape them by doubling them; for example: passThrough = "readonly = ""Yes"" ".

Any form field name, from the cfform tag or an HTML form, that ends in one of the following suffixes invokes server-side form validation:

Do not use these suffixes for your field names.

For more information, see the Retrieving and Formatting Data chapter in Developing ColdFusion MX Applications with CFML.

Incorporating HTML form tags

The cfform tag lets you incorporate these standard HTML elements:

Example

<h3>cfform Example</h3>
<cfif IsDefined("form.oncethrough") is "Yes">
  <cfif IsDefined("form.testVal1") is True>
  <h3>Results of Radio Button Test</h3>
  <cfif form.testVal1 is "Yes">Your radio button answer was yes</cfif>
  <cfif form.testVal1 is "No">Your radio button answer was no</cfif>
  </cfif>
  <cfif IsDefined("form.chkTest2") is True>
  <h3>Results of Checkbox Test</h3>
    Your checkbox answer was yes
  <cfelse>
    <h3>Results of Checkbox Test</h3>
    Your checkbox answer was no
  </cfif>
  <cfif IsDefined("form.textSample") is True 
   AND form.textSample is not "">
  <h3>Results of Credit Card Input</h3>
    Your credit card number, <cfoutput>#form.textSample#</cfoutput>, 
was valid under the MOD 10 algorithm.
  </cfif>
  <cfif IsDefined("form.sampleSlider") is "True">
  <h3>You gave this page a rating of <cfoutput>#form.sampleSlider#
   </cfoutput></h3>  
  </cfif>
  <hr noshade>
</cfif>
<!--- begin by calling the cfform tag --->
<cfform action = "cfform.cfm">
<table>
<tr>
  <td>
  <h4>This example displays radio button input type for cfinput.</h4>
  Yes <cfinput type = "Radio" name = "TestVal1" value = "Yes" checked>
  No <cfinput type = "Radio" name = "TestVal1" value = "No">
  </td>
</tr>
<tr>
  <td>
  <h4>This example displays checkbox input type for cfinput.</h4>
  <cfinput type = "Checkbox" name = "ChkTest2" value = "Yes">
  </td>
</tr>
<tr>
  <td>
  <h4>This shows client-side validation for cfinput text boxes.</h4>
  <br>(<I>This item is optional</i>)<br>
  Please enter a credit card number:
  <cfinput type = "Text" name = "TextSample" 
    message = "Please enter a Credit Card Number" 
    validate = "creditcard" required = "No">
  </td>
</tr>
<tr>
  <td>
  <h4>This example shows the use of the cfslider tag.</h4>
  <p>Rate your approval of this example from 1 to 10 by sliding control.
  <p>1 <cfslider name = "sampleSlider" 
      label = "Sample Slider" range = "1,10"
      message = "Please enter a value from 1 to 10" 
      scale = "1" bold = "No"
      italic = "No" refreshlabel = "No"> 10
  </td>
</tr>
</table>
<p><input type = "submit" name = "submit" value = "show me the result">
<input type = "hidden" name = "oncethrough" value = "Yes">
</cfform>
</body>
</html> 

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

Version 6

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

Comments


rbils@amkor.com said on Jul 8, 2002 at 3:23 AM :
Two issues here. First, the ONLOAD attribute is not a standard attribute in the HTML FORM tag. It looks like it's supposed to invoke functionality within the CFFORM tag and it's associated JS flie. However, it's broken. Setting ONLOAD="yes" always causes an error when the form is submitted as _CF_signalLoad() is never called in the cfform.js file (unless you add an onLoad to your page's BODY attribute.

The second issue is that this documentation lists METHOD as an attribute. This implies you can specify GET or POST. This is not the case as POST is hardcoded into the CFFORM tag.

If you need a test case for bug number 1 above, email me and I'll be happy to work with your engineers.
rbils@amkor.com said on Jul 8, 2002 at 3:25 AM :
Make that three bugs. The error message generated by MX if you pass an attribute that doesn't exist lists out the attributes that the tag accepts. One of these is ENABLEJAR. This attribute isn't documented here, and I looked in the form.cfm template used by MX, and it's listed as an attribute, but it isn't implemented in the code anywhere!
starkami said on Jul 7, 2003 at 10:50 AM :
There is a problem I have found with CFFORM and CFINPUT tags.If you set define a cfform tag on a page and define all your cfinput tags in a componenet and then calls this component with in the cfform tag, It will not compile and will generate error. While if I use html input tag instead of cfinput tag then its works. I have code which demonstrates this problem. If any one intrested, can mail me.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt139.htm