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

cfform

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

Forms tags

<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"
standard HTML attributes>
...
</cfform>

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

ColdFusion MX:

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 for preprocessing data before form is submitted. See Developing ColdFusion MX Applications.

passThrough

Optional

 

Passes arbitrary attribute-value pairs to the HTML code that is generated for the tag. You can use either of the following formats:

passthrough="title=""myTitle"""

passthrough='title="mytitle"'

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

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

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 Retrieving and Formatting Data in Developing ColdFusion MX Applications.

Incorporating HTML form tags

The cfform tag lets you incorporate these standard HTML elements:

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

Contents > CFML Reference > ColdFusion Tags > cfform 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


jrunrandy said on Oct 17, 2003 at 12:09 PM :
There is a hotfix for cfform, available at http://www.macromedia.com/support/coldfusion/ts/documents/cfform_hotfix.htm

The fix contains an updated JAR file that resolves the following issues with the cfform applets:

* Required fields in cfform / cfinput are not processed in the order they are defined within the form.
* When more than one image is specified for cftreeitem, the first specified image is displayed for all levels.
* Using cftree and cftreeitem throws Java ClassCastException error.
No screen name said on Dec 4, 2003 at 12:33 PM :
I transfered sites from one server to another server. Ever since, all the Submit buttons on all <cfforms> are throwing an error.
jrunrandy said on Dec 4, 2003 at 12:42 PM :
I think this has to do with needing to copy /CFIDE/scripts/cfform.js to your new web server. Check out http://www.macromedia.com/support/coldfusion/ts/documents/cfform_multihomed.htm for more details.
markus einfinger said on Feb 12, 2004 at 3:41 AM :
Can I use "method=get" with CFFORM?
halL said on Feb 12, 2004 at 1:12 PM :
No you can not.
halL said on Feb 12, 2004 at 1:13 PM :
I forgot to add: This is a known enhancement request.
No screen name said on Apr 12, 2004 at 10:52 PM :
hi all.
i am workin with coldfusion-cfgrid .i have added cfgrid and the data is form database.my problem is ,i want to add a column to grid not from the database in the same grid..plz give me a reply

reguards
surej
CRJAngel said on Aug 20, 2004 at 8:57 AM :
I have added the cfform.js to a scrips folder in my webroot. However I have a selectbox which will not validate as required even though I have it set to required. Any insight on this? All other options in CFform are validating and there is a option to set required on SelectBoxes but it does not work.
PrinceNamor said on Oct 5, 2004 at 2:23 AM :
Why cant u use method="get" in CFForm ?
its a valid in HTML and it is sometimes needed when u need a FORM's to post variables to the URL.

Shouldnt this be considered a "flaw" in the tag as it is supposed to mimic HTML's <form> tag?
jrunrandy said on Oct 5, 2004 at 7:08 AM :
PrinceNamor: Using Method="get" places all form variables in the URL string and is not considered to be a best practice. CFFORM simply enforces this best practice.
wotg said on Oct 27, 2004 at 4:08 PM :
If you can't easily get your webhost to give you a copy of cfform.js, you can probably steal it from somewhere else.
e.g:
http://example.com/CFIDE/scripts/cfform.js (just find a site running CF)
No screen name said on Nov 30, 2004 at 9:11 AM :
So since there is no "GET" method for CFFORM, what's the best way to have the form not have to be completely refilled out if the user clicks "BACK" after they are on the next page??
BlueSpline said on Apr 4, 2005 at 9:18 PM :
Does PreserveData work? I want to use it with checkboxes, I've tried setting it to "yes" and "true" but not held the data when I post the form to itself. Is there something else that I need to do in the individual field to reload the previous value?

I'm sure I've previously tried this with other CFinput tyoes without success.
BlueSpline said on Apr 4, 2005 at 10:16 PM :
PreserveData does work on CFselect, but only if the user selects a single option.
jrunrandy said on Apr 12, 2005 at 1:05 PM :
BlueSpline,
I'm sorry to say that I don't know the answer to your question. Do these discussions help?
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/dynamic5.htm
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/dynamic6.htm

Also, I noticed the following "changed in CFMX" note for cfinput (http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-p65.htm):

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.
winjer2k said on Jan 5, 2007 at 8:43 AM :
There is a workaround for getting <cfform> to use the GET method instead of POST. Use Javascript to set the form's method before it is submitted:

<script language="JavaScript">
function submitHandler(theForm) {
theForm.method = "GET";
}
</script>

<cfform action="foo.cfm" onSubmit="submitHandler(_CF_this);">
...


BTW, jrunrandy said that using "GET" as not best practice. This is incorrect. POST should be used when data on the server is to be changed in some way. GET should be used to simply request data. So, for instance, an address lookup form would use GET, while a user profile page should use POST.

 

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-p38.htm