ColdFusion 9.0 Resources |
Building Flash formsYou build Flash forms using standard ColdFusion form tags, plus the cfformgroup and cfformitem tags. These tags create the elements of the form, as follows:
Flash forms follow a hierarchical structure of containers and children.
Adding text, images, rules, and space with the cfformitem tagBecause Flash forms do not support inline HTML, you use the cfformitem tag to add text blocks and horizontal and vertical rules to your form. (Flash form controls, such as cfinput, use the label or value attribute to specify text labels.) You can also use the cfformitem tag to add spacers between visual form elements. The cfformitem type="hrule" and cfformitem type="vrule" tags put horizontal and vertical rules in the form. You can specify the rule thickness, color, and shadow characteristics by using style specifications. For more information on specifying rule styles, see Styles for cfformitem with hrule or vrule type attributes in ColdFusion Flash Form Style Reference in the CFML Reference. The cfformitem type="spacer" tag puts a blank space of the specified height and width on the form. This tag type does not use styles; it can be useful in improving the form appearance by helping you control the form layout. The cfformitem type="text" tag lets you insert plain text in the form You can use the style attribute to apply a consistent format to the text. The cfformitem type="html" tag lets you insert formatted text and images in the form. You can include basic HTML-style formatting tags in the body of this tag to add images and to format and style the text. You can use the following formatting tags and attributes in the body of a cfformitem type="html" tag:
The img tag supports the following attributes:
Note: Because of the Flash dynamic sizing rules, to
ensure that the image displays properly, you sometimes have to specify
the formitem tag height attribute
and the width and height attributes
for the form or the containing cfformgroup tag.
Also, the image always displays on a new line, not inline with text,
and text that follows the image in your code occupies any available
space to the right of the image.
The textformat tag is specific to Flash, and has the following attributes:
For detailed descriptions of these tags, see the Flash documentation. The following code creates a simple Flash form that consists of a formatted text area surrounded by horizontal rules: <cfform name="myform" height="220" width="400" format="Flash" > <!--- Use text formitem tag with style specifications for the heading. ---> <cfformitem type="text" style="fontWeight:bold; fontSize:14;"> Flash form with formatted text and rules </cfformitem> <!--- The spacer adds space between the text and the rule ---> <cfformitem type="spacer" height="2" /> <cfformitem type="hrule" /> <cfformitem type="html"> <b><font color="#FF0000" size="+4" face="serif"> This form has formatted text, including:</font></b><br> <textformat blockindent="20" leading="2"> <li>colored text</li> <li><i>italic and bold text</i></li> <li>a bulleted list in an indented block</li> </textformat> <p><b>The text is preceded and followed by horizontal rules</b></p> It also has a link to a web page.</b><br> <a href="http://www.adobe.com/" target="_blank"> <font color="#0000FF"><u> This link displays the Adobe home page in a new browser window </u></font></a> </cfformitem> <cfformitem type="spacer" height="2"/> <cfformitem type="hrule"/> </cfform> Using the cfformgroup tag to structure formsColdFusion provides form group container types that provide basic structure to a Flash form. You specify these types in the type attribute of the cfformgroup tag. Use the following container types to control the layout of controls and groups of controls:
For more information on using the accordion, tabnavigator, and pagecfformgroup types, see Creating complex forms with accordion and tab navigator containers. Example: structuring with the cfformgroup tagThe following example shows a form with an hdividedbox container with two vbox containers. The left box uses a horizontal container to arrange two radio buttons. The right box uses a tile container to lay out its check boxes. You can drag the divider handle to resize the two boxes. When you submit the form, the ColdFusion page dumps the Form scope to show the submitted data. <cfif Isdefined("Form.fieldnames")> <cfdump var="#form#" label="form scope"> <br><br> </cfif> <cfform name="myform" height="200" width="460" format="Flash" skin="HaloBlue"> <cfformitem type="html" height="20"> <b>Tell us your preferences</b> </cfformitem> <!--- Put the pet selectors to the left of the fruit selectors. ---> <cfformgroup type="hdividedbox" > <!--- Group the pet selector box contents, aligned vertically. ---> <cfformgroup type="VBox"height="130"> <cfformitem type="text" height="20"> Pets: </cfformitem> <cfformgroup type="vertical" height="80"> <cfinput type="Radio" name="pets" label="Dogs" value="Dogs" checked> <cfinput type="Radio" name="pets" label="Cats" value="Cats"> </cfformgroup> </cfformgroup> <!--- Group the fruit selector box contents, aligned vertically. ---> <cfformgroup type="VBox" height="130"> <cfformitem type="text" height="20"> Fruits: </cfformitem> <cfformgroup type="tile" height="80" width="190" label="Tile box"> <--- Flash requires unique names for all controls ---> <cfinput type = "Checkbox" name="chk1" Label="Apples" value="Apples"> <cfinput type="Checkbox" name="chk2" Label="Bananas" value="Bananas"> <cfinput type="Checkbox" name="chk3" Label="Pears" value="Pears"> <cfinput type="Checkbox" name="chk4" Label="Oranges" value="Oranges"> <cfinput type="Checkbox" name="chk5" Label="Grapes" value="Grapes"> <cfinput type="Checkbox" name="chk6" Label="Cumquats" value="Cumquats"> </cfformgroup> </cfformgroup> </cfformgroup> <cfformgroup type="horizontal"> <cfinput type="submit" name="submit" width="100" value="Show Results"> <cfinput type="reset" name="reset" width="100" value="Reset Fields"> </cfformgroup> </cfform> Controlling sizes in Flash formsSizing elements in a Flash form is something of an art, rather than a science. As a general rule, if you don’t specify the height and width attributes, Flash tends to do a good job of laying out the form. However, keep in mind the following considerations:
Determine the sizes of a Flash form and its controls
Repeating Flash form elements based on query dataThe repeatercfformgroup type tells Flash Player to iterate over a query and create a set of the cfformgroup tag’s child controls for each row in the query. For each set of child controls, bind attributes in the child tags can access fields in the current query row. This cfformgroup type lets you create Flash forms where the number of controls can change based on a query, without requiring ColdFusion to recompile the Flash SWF file for the form. This significantly enhances server performance. Note: For more information on binding data, see Binding data in Flash forms.
Optionally, you can specify a start row and a maximum number of rows to use in the repeater. Unlike most ColdFusion tags, repeater index values start at 0, not 1. To specify a repeater that starts on the first line of the query object and uses no more than 15 rows, use a tag such as the following: <cfformgroup type="repeater" query="q1" startrow="0" maxrows="15"> One example that can use a repeater is a form that lets a teacher select a specific class and update the student grades. Each class can have a different number of students, so the form must have a varying number of input lines. Another example is a shopping cart application that displays the product name and quantity ordered and lets users change the quantity. The following example uses the cfformgroup tag with a repeatertype attribute value to populate a form. It creates a query, and uses the repeater to iterate over a query and create a firstname and lastname input box for each row in the query. <cfif IsDefined("Form.fieldnames")> <cfdump var="#form#" label="form scope"> <br><br> </cfif> <cfscript> q1 = queryNew("id,firstname,lastname"); queryAddRow(q1); querySetCell(q1, "id", "1"); querySetCell(q1, "firstname", "Rob"); querySetCell(q1, "lastname", "Smith"); queryAddRow(q1); querySetCell(q1, "id", "2"); querySetCell(q1, "firstname", "John"); querySetCell(q1, "lastname", "Doe"); queryAddRow(q1); querySetCell(q1, "id", "3"); querySetCell(q1, "firstname", "Jane"); querySetCell(q1, "lastname", "Doe"); queryAddRow(q1); querySetCell(q1, "id", "4"); querySetCell(q1, "firstname", "Erik"); querySetCell(q1, "lastname", "Pramenter"); </cfscript> <cfform name="form1" format="flash" height="220" width="450"> <cfselect label="select a teacher" name="sel1" query="q1" value="id" display="firstname" width="100" /> <cfformgroup type="repeater" query="q1"> <cfformgroup type="horizontal" label="name"> <cfinput type="Text" name="fname"bind="{q1.currentItem.firstname}"> <cfinput type="Text" name="lname" bind="{q1.currentItem.lastname}"> </cfformgroup> </cfformgroup> <cfinput type="submit" name="submitBtn" value="Send Data" width="100"> </cfform> Creating complex forms with accordion and tab navigator containersThe accordion and tabnavigator attributes of the cfformgroup tag let you construct complex forms that would otherwise require multiple HTML pages. With accordions and tab navigator containers, users can switch among multiple entry areas without submitting intermediate forms. All data that they enter is available until they submit the form, and all form elements load at one time. An accordion container places each logical form page on an accordion pleat. Each pleat has a label bar; when the user clicks a bar, the current page collapses and the selected page expands to fill the available form space. The following image shows a three-pleat accordion, open to the middle pleat, Preferences: A tab navigator container places each logical form page on a tabbed frame. When the user clicks a tab, the selected page replaces the previous page. The image in About Flash forms shows a tab navigator container. The following example generates a two-tab navigator container that gets contact information and preferences. You can change it to an accordion container by changing the type attribute of the first cfformgroup tag from tabnavigator to accordion. To prevent the accordion from having scroll bars, increase the cfform tag height attribute to 310 and the tabnavigator tag height attribute to 260. <cfif IsDefined("Form.fieldnames")> <cfdump var="#form#" label="form scope"> <br><br> </cfif> <br> <cfform name="myform" height="285" width="480" format="Flash" skin="HaloBlue"> <cfformgroup type="tabnavigator" height="240" style="marginTop: 0"> <cfformgroup type="page" label="Contact Information"> <!--- Align the first and last name fields horizontally. ---> <cfformgroup type="horizontal" label="Your Name"> <cfinput type="text" required="Yes" name="firstName" label="First" value="" width="100"/> <cfinput type="text" required="Yes" name="lastName" label="Last" value="" width="100"/> </cfformgroup> <cfformitem type="hrule" /> <cfformitem type="HTML"><textformat indent="95"><font size="-2"> Flash fills this field in automatically. You can replace the text. </font></textformat> </cfformitem> <!--- The bind attribute gets the field contents from the firstName and lastName fields as they get filled in. ---> <cfinput type="text" name="email" label="email" bind="{firstName.text}.{lastName.text}@mm.com"> <cfformitem type="spacer" height="3" /> <cfformitem type="hrule" /> <cfformitem type="spacer" height="3" /> <cfinput type="text" name="phone" validate="telephone" required="no" label="Phone Number"> <cfinput type="datefield" name="mydate1" label="Requested date"> </cfformgroup> <cfformgroup type="page" label="Preferences" style="marginTop: 0"> <cfformitem type="html" height="20"> <b>Tell us your preferences</b> </cfformitem> <!--- Put the pet selectors to the left of the fruit selectors. ---> <cfformgroup type="hdividedbox" > <!--- Group the pet selector box contents, aligned vertically. ---> <cfformgroup type="VBox"height="130"> <cfformitem type="text" height="20"> Pets: </cfformitem> <cfformgroup type="vertical" height="80"> <cfinput type="Radio" name="pets" label="Dogs" value="Dogs" checked> <cfinput type="Radio" name="pets" label="Cats" value="Cats"> </cfformgroup> </cfformgroup> <!--- Group the fruit selector box contents, aligned vertically. ---> <cfformgroup type="VBox" height="130"> <cfformitem type="text" height="20"> Fruits: </cfformitem> <cfformgroup type="tile" height="80" width="190" label="Tile box"> <--- Flash requires unique names for all controls. ---> <cfinput type = "Checkbox" name="chk1" Label="Apples" value="Apples"> <cfinput type="Checkbox" name="chk2" Label="Bananas" value="Bananas"> <cfinput type="Checkbox" name="chk3" Label="Pears" value="Pears"> <cfinput type="Checkbox" name="chk4" Label="Oranges" value="Oranges"> <cfinput type="Checkbox" name="chk5" Label="Grapes" value="Grapes"> <cfinput type="Checkbox" name="chk6" Label="Kumquats" value="Cumquats"> </cfformgroup> </cfformgroup> </cfformgroup> </cfformgroup> </cfformgroup> <cfformgroup type="horizontal"> <cfinput type = "submit" name="submit" width="100" value = "Show Results"> <cfinput type = "reset" name="reset" width="100" value = "Reset Fields"> </cfformgroup> </cfform> |