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

Passing Arrays

Engaged ,
Feb 06, 2008 Feb 06, 2008

Copy link to clipboard

Copied

I have a form whose fieldnames are generated by an array created by a query. I then duplicate that array as a session scope array so after I submit the form I can evaluate() the form field names and get the submitted values. (see code below for clarification)



I have decided (thanks to the advice here: http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=7&threadid=1335323&am... to incorporate cfthread to make this process much faster for my users. However, upon testing I have learned that I need to use some kind of a template for this to go over well, I can't just put a cfthread tag around the code I want to be done. It seems this will require me to get not only the array but also the form results to a template somewhere.

I know I can keep the array as a session scoped array and make sure the array name is unique, but I'm still kind of nervous about this and would rather access it another way. Can I perhaps create a function that would accept an array? Also, I have no idea how to pass the form values.

I'm upgrading from 4.5 to 8 so I'm still learning about functions and threading and all that good stuff.

Thanks for your help!

TOPICS
Advanced techniques

Views

502

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 06, 2008 Feb 06, 2008

Copy link to clipboard

Copied

Your first paragraph suggests that you may have over-engineered your application. Also, if you use array notation on your formfields you don't need the evaluate function and your code will run faster.

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 ,
Feb 06, 2008 Feb 06, 2008

Copy link to clipboard

Copied

Don't I have to regenerate the form field names though?

If I have over-engineered this problem, can you give me an idea on how you would generate a form from a query result then compare the query returned values with the submitted values, and update accordingly?

The query returns an id, a code and a value. The form field names are the code. When new values are submitted the page compares the values returned by the query to the submitted values.

Regardless, this doesn't help me with getting this data to a template.

Thanks though. I have reworked this code a number of times and will continue to do so.

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 06, 2008 Feb 06, 2008

Copy link to clipboard

Copied

to generate form fields from a query output?

<cfoutput query="something" >
<input name="thename#currentrow#">

To read them when the form is submitted (I probably have the syntax wrong here.

<cfoutput>
<cfloop list'"#form.fieldlist#" index="ii">
<cfif left(form[thename#ii#], 7 is "thename">
do something

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 ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

Thanks, the fieldnames suggestion helped a lot. I'm still having trouble passing this data to something useful. I've come up with the attached code.

. . . but I keep getting the error "Element data.fieldnames is undefined in a Java object of type class coldfusion.filter.FormScope. " The error is on line 6 though, instead of line 5 . . .

thoughts?

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 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

Start with looking at what was passed to your function. cfdump var="#arguments#" gets you started.

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 ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

When I do a

cfdump var=#form#

in the main .cfm page before i call cfinvoke it has just what I expected, the form struct with all of its data. If I do

cfdump var=#data# (where data is the name of the argument)

nothing shows up, regardless of what I set the output parameter to.

I don't understand. Am I passing it incorrectly? Am I using it incorrectly once passed in? cfdump game me what I expected, but perhaps it should be showing up when I dump it in the .cfc?

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 ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

Actually, nevermind, I still had the cfinvoke block commented out.

I uncommented it and the cfdump inside the cfc also displays exactly as I think it should, with the struct data.

So it looks like I'm sending and receive the information correctly, but I'm still getting the same error.

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 ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

LATEST
Ok, so something stupid, I forgot to put data.fieldnames in quotes . . .

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