Builds a form with CFML custom control tags; these provide more functionality than standard HTML form input elements.
<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:
enableCAB
attribute. It might not work, and might cause an error, in later releases. name
and action
attributes to optional.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.
Applies to these controls:
|
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:
|
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:
cfinput
Creates and validates an input element (radio button, text box, check box)cfselect
Creates a drop-down list boxcfslider
Creates a slider control (Java support required)cftextinput
Creates a text input box (Java support required)cftree
Creates a tree control (Java support required)cfgrid
Creates a grid control to display tabular data (Java support required)cfapplet
Embeds a registered Java applet (Java support required)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.
The cfform
tag lets you incorporate these standard HTML elements:
form
tag that cfform
outputs in the page. For example, you can use form
tag attributes like target
with cfform
. Other pass-through attributes include CLASS, ENCTYPE, ID, ONLOAD, ONRESET, and STYLE.form
tag. For example, you can use the HTML input
tag to create a submit button in a cfform
, without the other features of cfinput
:<cfform> <input type = "Submit" value = " update... "> </cfform>
<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>