Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Form Name with a Variable

Community Beginner ,
Feb 16, 2010 Feb 16, 2010

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?

TOPICS
Advanced techniques
342
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 16, 2010 Feb 16, 2010

You are probably looking for array syntax.

<cfoutput>#form["field_" & id]#</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 16, 2010 Feb 16, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2010 Feb 17, 2010
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources