6 Replies Latest reply on Oct 30, 2006 10:29 AM by dave.cozens

    Dynamic CFInput Names Using Arrays

    kodemonki Level 1
      I am trying to assign text input to array values. To do this I use the below code. When I try to run the page I get the error message: "The element at position 16 in dimension 1 of object "reasonArray" cannot be found. That dimension of the object is empty. Please, modify the index expression." The elements do not go in order as the order is based off of a different dynamic part of the form.

      My question: of course that position is empty, I'm trying to get it filled! Why is it giving me an error?

        • 1. Re: Dynamic CFInput Names Using Arrays
          At this point you haven't actually got any array values set. What you're doing is creating a form field with the name parameter set to #reasonArray[report_id]#". This array has not been populated with anything, so it's failing.

          What are you trying to achieve?
          • 2. Re: Dynamic CFInput Names Using Arrays
            kodemonki Level 1
            I'm trying to set the array index equal to the value entered in the textbox. Later I need to send an e-mail that goes through each report id, sees if it's been selected, and if it has, lists the reason for that report.

            Please let me know if this still isn't clear.

            Thank you!
            • 3. Re: Dynamic CFInput Names Using Arrays
              jdeline Level 1
              In my experience, you must directly populate an array element with an assignment. You might try the following: name="R#report_id#" In your action page, you can easiely assign the Rnnn to the reasonArray, using nnn as the index into the array.

              BTW, you have a logic error in the first part of your code. If the <CFIF> statement is FALSE, you do not get the <TR tag, and style="font-size:11;"> is hanging out.
              • 4. Re: Dynamic CFInput Names Using Arrays
                dave.cozens Level 1
                OK, so the array serves no purpose on the form page, since you don't yet have any data. You need that on the action page.

                Hopefully this will give you some pointers...

                Form Page

                <Cfoutput query="getReports">
                <input type="text" name="data_#getReports.report_ID#">
                <inputy type="hidden" name="report_ids" value="#report_id#">

                Action Page
                <Cfloop list="#report_ids#" index="report_id">
                <cfset thisReportData=form["data_"&report_id]>
                <cfoutput><br>#report_id# = #thisReportData#</cfoutput>
                • 5. Re: Dynamic CFInput Names Using Arrays
                  kodemonki Level 1
                  Thank you so much! That was actually my backup solution that I've been using, but it doesn't work without the form[] so I've been writing everything out, which defeats the whole purpose of dynamic code. Do you know where I can find documentation on that part?

                  Also, jdeline, thanks for your comment about the logic error. I edited a lot of the unnecessary code to make the post more readable and turns out it was just more confusing. Thanks though!
                  • 6. Re: Dynamic CFInput Names Using Arrays
                    dave.cozens Level 1
                    Honestly I'm not sure about the documentation part.

                    Basically, there's no difference between: -
                    form.my_field and form["my_field"]

                    They both reference the same value. But the array style notation is much more versatile and totally dynamic (plus avoids using evaluate - which is what we had to do many years ago!)

                    You can do the same thing with all the variable scopes


                    Use cfdump to see more, for example
                    <cfdump var="#server#">
                    <cfdump var="#variables#">
                    <cfdump var="#form#">