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

Form Name with a Variable

Community Beginner ,
Feb 16, 2010 Feb 16, 2010

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?

TOPICS
Advanced techniques

Views

314

Translate

Translate

Report

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

Copy link to clipboard

Copied

You are probably looking for array syntax.

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

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
Documentation