6 Replies Latest reply on Aug 24, 2008 1:12 AM by BKBK

    Dynamic Variables

      I am trying to use data I pulled from my data base to assemble variable names. The first part is a call to the form. scope, the second part is query data, and the third part is hard coded part of the naming structure.


      Tried using:

      This comes out as:

      This is the correct variable name but I can not get the value out of it.

      Any help would be great.
        • 1. Re: Dynamic Variables
          Level 7
          try this way:

          Azadi Saryev
          • 2. Re: Dynamic Variables
            Dan Bracuk Level 5
            It's not clear what you are trying to do.

            As near as I can figure out, you are submitting a form to a page. That gives you a form structure with the names and values of what was submitted.

            You are also running at least one select query. That will give you a query object that is totally separate from the form.

            Are you now trying to add an array to the form scope? If you actually succeed, what are you going to do with it?
            • 3. Re: Dynamic Variables
              imaaxa Level 1
              I am trying to process the information from a form. I am doing a recap of the information that was collected, and giving the user an opportunity to correct it be for it is recorded.

              It is broken up into "categories". Each "categories" has different number of "sub category 1s" and "sub category 2s". The form entry names use the same naming structure through out the form.

              Example "category 1" would have a name like: animal_sub_cat, and vegetable_sub_cat, where animal_ and vegetable_ part of the name would come from the database query and the sub_cat would be hard coded into the page.

              I am needing to be able to replace that animal_ part of the name with the query data, and be able to submit that to a <cfif> tag so it can evaluate the value from that variable.
              • 4. Re: Dynamic Variables
                Dan Bracuk Level 5
                If you make the query a session variable it will be available on page3. That might simplify your app.
                • 5. Re: Dynamic Variables
                  you can use the following functions to set and read the variables with dynamic names:

                  <!--- ============================================================== --->
                  <cffunction name="field_set" output="No">
                  <cfargument name="field" type="string" default="">
                  <cfargument name="value" type="string" default="">

                  <cfset "#field#"= value>
                  <!--- ============================================================== --->
                  <cffunction name="field_get" output="No">
                  <cfargument name="field" type="string" default="">
                  <cfif isdefined("#field#") IS TRUE>
                  <cfreturn evaluate("#field#")>
                  • 6. Re: Dynamic Variables
                    BKBK Adobe Community Professional & MVP
                    I agree with Dan. You apparently store a query into a form, or are attempting to. It puts a question mark on whatever it is you're doing.

                    I would start afresh. Define the problem, without mentioning technical details like forms and queries. Find the solution in terms of form/form-fields, query/query-columns, and so on.