8 Replies Latest reply on Feb 7, 2008 10:23 AM by kodemonki

    Passing Arrays

    kodemonki Level 1
      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&forumid=1) 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!

        • 1. Re: Passing Arrays
          Dan Bracuk Level 5
          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.
          • 2. Re: Passing Arrays
            kodemonki Level 1
            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.
            • 3. Re: Passing Arrays
              Dan Bracuk Level 5
              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.

              <cfloop list'"#form.fieldlist#" index="ii">
              <cfif left(form[thename#ii#], 7 is "thename">
              do something
              • 4. Passing Arrays
                kodemonki Level 1
                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 . . .

                • 5. Re: Passing Arrays
                  Dan Bracuk Level 5
                  Start with looking at what was passed to your function. cfdump var="#arguments#" gets you started.
                  • 6. Re: Passing Arrays
                    kodemonki Level 1
                    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?
                    • 7. Re: Passing Arrays
                      kodemonki Level 1
                      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.
                      • 8. Re: Passing Arrays
                        kodemonki Level 1
                        Ok, so something stupid, I forgot to put data.fieldnames in quotes . . .