Copy link to clipboard
Copied
I have a form that I built with a cfloop and I want to be able to name the field names
like this field_#ID# as it does the loop. Is there a way to do this?
Copy link to clipboard
Copied
You are probably looking for array syntax.
<cfoutput>#form["field_" & id]#</cfoutput>
Copy link to clipboard
Copied
Ian's answer pertained to processing the form. To create it, assuming you were looping through a query, change the cfloop tag to a cfoutput tag.
Copy link to clipboard
Copied
The approach for the form tag is slightly different from that of cfform. Put the following code in a page, open it and view the page source in the browser.
<form>
<cfloop from = "1" to = "5" index="idx">
<cfoutput><input name="myTxtBox_#idx#" type="text"></cfoutput><br>
</cfloop>
</form>
<cfform>
<cfloop from = "1" to = "5" index="idx">
<!--- cfoutput unnecessary --->
<cfinput name="myFormField_#idx#" type="text"><br>
</cfloop>
</cfform>