CFFORM

CFFORM allows you to build a form with CFML custom control tags that provide much greater functionality than standard HTML form input elements.

Syntax

<CFFORM NAME="name"
    ACTION="form_action"
    ENABLECAB="Yes/No"
    ONSUBMIT="javascript"
    TARGET="window_name"
    ENCTYPE="type"
    PASSTHROUGH="HTML_attributes">

...
</CFFORM>

NAME

Optional. A name for the form you are creating.

ACTION

Required. The name of the ColdFusion page that will be executed when the form is submitted for processing.

ENABLECAB

Optional. Yes or No. Allows users to download the Microsoft cabinet (*.cab) file(s) containing the Java classes used for Java applet-based CFFORM controls. If Yes, on opening the page, users are asked if they want to download the CAB file.

ONSUBMIT

Optional. JavaScript function to execute after other input validation returns. Use this attribute to execute JavaScript for preprocessing data before the form is submitted. See Developing Web Applications with ColdFusion for information on using JavaScript for form validation.

TARGET

Optional. The name of the window or window frame where the form output will be sent.

ENCTYPE

Optional. The MIME type used to encode data sent via the POST method. The default value is application/x-www-form-urlencoded. It is recommended that you accept the default value. This attribute is included for compatibility with the HTML FORM tag.

PASSTHROUGH

Optional. HTML attributes that are not explicitly supported by CFFORM. If you specify an attribute and its value, the attribute and value are passed to the HTML code that is generated for the CFINPUT tag. See the Usage section for more information about specifying values.

Usage

The following custom control tags are available:

You can add standard and dynamic HTML FORM tag attributes and their values to the CFFORM tag by using the PASSTHROUGH attribute. These attributes and values are passed directly 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 " " "

The ENABLECAB attribute is supported only for MS Internet Explorer clients that have Authenticode 2.0 installed. Authenticode 2.0 can be downloaded from http://www.microsoft.com/ie/security/authent2.htm.

Note These CAB files are digitally signed using VeriSign digital IDs to ensure file security.

Incorporating HTML form tags

CFFORM allows you to incorporate standard HTML in two ways:

For example, you use a standard HTML INPUT tag to create a submit button in a CFFORM:

<CFFORM
    <INPUT TYPE="Submit" VALUE=" Update... ">
</CFFORM>

Example

<!--- This example shows the use of CFINPUT controls in
a CFFORM --->
<HTML>
<HEAD>
<TITLE>
CFFORM Example
</TITLE>
</HEAD>

<BODY>
<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" METHOD="POST" ENABLECAB="Yes">

<TABLE>
<TR>
    <TD>
    <H4>This example displays the radio button input type
    for CFINPUT.</H4>
    Yes <CFINPUT TYPE="Radio" NAME="TestVal1" VALUE="Yes" CHECKED="yes">
    No <CFINPUT TYPE="Radio" NAME="TestVal1" VALUE="No">
    </TD>
</TR>

<TR>
    <TD>
    <H4>This example displays the checkbox input type for CFINPUT.</H4>
    <CFINPUT TYPE="Checkbox" NAME="ChkTest2" VALUE="Yes">
    </TD>
</TR>

<TR>
    <TD>
    <H4>This example shows a 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 the
      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>