User Guide

Table Of Contents
638 Chapter 27: Building Dynamic Forms with cfform Tags
The cftree form variables
The
cftree tag lets you force a user to select an item from the tree control by setting the
required attribute to Yes. With or without the required attribute, ColdFusion passes two form
variables to the application page specified in the
cfform action attribute:
Form.treename.path Returns the complete path of the user selection, in the form:
[root]\node1\node2\node_n\value
Form.treename.node Returns the node of the user selection.
To return the root part of the path, set the
completepath attribute of the cftree tag to Yes;
otherwise, the path value starts with the first node. If you specify a root name for a tree item using
the
queryasroot tag, that value is returned as the root. If you do not specify a root name,
ColdFusion returns the query name as the root. If there is no query name, ColdFusion returns the
tree name as the root.
In the previous example, if the user selects the name "John Allen" in the tree, ColdFusion returns
the following form variables:
Form.tree1.path = 3\John Allen
Form.tree1.node = John Allen
The deptquery root does not appear in the path, because the cftree tag does not specify
completePath="Yes". You can specify the character used to delimit each element of the path
form variable in the
cftree delimiter attribute. The default is a backslash character (\).
Input validation
Although the
cftree tag does not include a validate attribute, you can use the required
attribute to force a user to select an item from the tree control. In addition, you can use the
onValidate attribute to specify your own JavaScript code to perform validation.
Structuring tree controls
Tree controls built with the
cftree tag can be very complex. Knowing how to specify the
relationship between multiple
cftreeitem entries helps you handle the most complex cftree
constructs.
Creating a one-level tree control
The following example consists of a single root and a number of individual items:
<cfquery name="deptquery" datasource="cfdocexamples">
SELECT Dept_ID, FirstName + ' ' + LastName
AS FullName
FROM Employee
ORDER BY Dept_ID
</cfquery>
<cfform name="form1" action="submit.cfm">
<cftree name="tree1">
<cftreeitem value="FullName"
query="deptquery"