Using the CFFORM Tag


Using the <CFFORM> Tag

This section describes how to use the <CFFORM> tag to create dynamic forms in CFML. Many <CFFORM> controls offer input validation attributes to validate end user entry, selection, or interaction. As a result, you don't have to write separate CFML code specifically for input validation.

Besides standard HTML form controls, the <CFFORM> tag allows you to create forms that contain these controls:

  • Text boxes of which you can specify the appearance, such as fonts and colors.

  • Text inputs that allow you to validate the data entered into the control.

  • Predefined ColdFusion Java applet-based controls that include trees, sliders, and grids.

  • Custom Java applets that act as form elements.

ColdFusion uses <CFFORM> tags to generate HTML forms dynamically and pass any HTML code that it finds in the form to the browser. ColdFusion passes the variable Form.fieldnames to the action page of the <CFFORM>. This variable contains the names of the form fields submitted from the form.

Table 4.3 summarizes the <CFFORM> controls that you can use in forms.

Table 4.3: <CFFORM> Controls

Control

Description

CFINPUT

Places radio buttons, checkboxes, text input boxes, and password entry boxes. It's equivalent to the HTML <INPUT> tag, with the added feature of input validation. It cannot create a Java applet.

CFTEXTINPUT

A Java applet-based text box.

CFSELECT

A drop-down list box. Equivalent to the HTML <SELECT> tag, with the added feature of input validation and data binding.

CFGRID

A Java applet-based control that creates a data grid that you can populate from a query or by defining the contents of individual cells of a table. You can also use grids to insert, update, and delete records from a data source.

CFSLIDER

A Java applet-based control that defines a slider control, which is most commonly used to select a value from a range of numeric values.

CFTREE

A Java applet-based control that defines a tree control and individual tree control items. A tree is most commonly used to display and select hierarchical data.

CFAPPLET

Embeds your Java applets in the form as if they were native ColdFusion tags.

Often, you need to continue displaying the data entered by an end user in a form after the form has been submitted. The <CFFORM> attribute PRESERVEDATA specifies this to ColdFusion. Data is preserved in the <CFINPUT>, <CFSLIDER>, <CFTEXTINPUT>, and <CFTREE> controls. When an end user overrides the default value specified for a control in the form, the end user's input is preserved.

You can retain the data on a form when an action posts data to the same ColdFusion page as the form itself, and the control names are the same.

While using PRESERVEDATA, you need to keep these points in mind:

  • In <CFTREE>, PRESERVEDATA expands the tree to the previously selected element. To ensure that this works correctly, you must set the COMPLETEPATH attribute to TRUE.

  • PRESERVEDATA has no effect on <CFGRID>. If you populate the control from a query, you must update the data source before redisplaying the grid. The grid then displays the updated database information.

Note

Applet-based controls use JavaScript and Java to display their content. These applets use the Java plug-in to ensure consistent display across a variety of browsers. ColdFusion downloads and installs this browser plug-in, if necessary. As a result, these controls are independent of the level of Java support provided by the browser. These controls also use JavaScript to return data to ColdFusion. If you disable JavaScript in your browser, ColdFusion can't run the forms that contain these controls properly. In this case, although the controls continue to be displayed, data return and validation don't work and you receive a JavaScript error.




Macromedia ColdFusion MX. Professional Projects
ColdFusion MX Professional Projects
ISBN: 1592000126
EAN: 2147483647
Year: 2002
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net