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

Extracting a value from indexed form field

Explorer ,
Aug 30, 2007 Aug 30, 2007

Copy link to clipboard

Copied

I have a form that contains a <cfoutput> which lists several records. I want to pass the value of the form field to my action page.

In the form the "name" of the form field is set as follows: name="guests#RecordCounter#" where RecordCounter is the index number.

In my action form I have the follow statement which doesn't work: <cfset guests = evaluate(form.guests#i#)> where i is the counter. How do I extract the value from this form field.

Any help would be greatly appreciated.
TOPICS
Advanced techniques

Views

425

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

correct answers 1 Correct answer

Engaged , Aug 30, 2007 Aug 30, 2007
Ah yes. cf_dev2's comment sort of highlighted for me what was wrong with your code. You missed the quotes from your evaluate() statement. And as cf_dev2 pointed out, it's actually preferrable to use a direct structure/key reference, instead of evaluate. Nevertheless, you could do this in one of 4 ways as I see it:

<cfset guests = evaluate( "form.guests#i#" )>
<cfset guests = evaluate( "form.guests"&i )>
<cfset guests = form["guests#i#"] >
<cfset guests = form["guests"&i] >

I personally pre...

Votes

Translate

Translate
Engaged ,
Aug 30, 2007 Aug 30, 2007

Copy link to clipboard

Copied

Try a <cfdump var="#form#"> to see what's getting posted...

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
Guide ,
Aug 30, 2007 Aug 30, 2007

Copy link to clipboard

Copied

Use array notation

<cfset guests = form["guests#i#"] >

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
Engaged ,
Aug 30, 2007 Aug 30, 2007

Copy link to clipboard

Copied

Ah yes. cf_dev2's comment sort of highlighted for me what was wrong with your code. You missed the quotes from your evaluate() statement. And as cf_dev2 pointed out, it's actually preferrable to use a direct structure/key reference, instead of evaluate. Nevertheless, you could do this in one of 4 ways as I see it:

<cfset guests = evaluate( "form.guests#i#" )>
<cfset guests = evaluate( "form.guests"&i )>
<cfset guests = form["guests#i#"] >
<cfset guests = form["guests"&i] >

I personally prefer the last one.

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
Explorer ,
Sep 02, 2007 Sep 02, 2007

Copy link to clipboard

Copied

LATEST
Thanks cf_dev2 and Grizzly9279 for your help - your solutions worked great!

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