The repeater
cfformgroup
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, cfrepeater
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 might 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 repeater
type
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>