Skip to main content
Inspiring
August 20, 2008
Question

Dynamic Variables

  • August 20, 2008
  • 5 replies
  • 474 views
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.

Example:
form.query_name.query_information_hard_coded_string

Tried using:
form.#query_name.query_information_#hard_coded_string

This comes out as:
form.query_name.query_information_hard_coded_string

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

Any help would be great.
Thanks
This topic has been closed for replies.

5 replies

BKBK
Community Expert
Community Expert
August 24, 2008
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.

Inspiring
August 23, 2008
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>
<!--- ============================================================== --->
<cffunction name="field_get" output="No">
<cfargument name="field" type="string" default="">
<cfif isdefined("#field#") IS TRUE>
<cfreturn evaluate("#field#")>
</cfif>
</cffunction>
Inspiring
August 20, 2008
If you make the query a session variable it will be available on page3. That might simplify your app.
Inspiring
August 20, 2008
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?
imaaxaAuthor
Inspiring
August 20, 2008
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.
Inspiring
August 20, 2008
try this way:
form[query_name['query_information_hard_coded_string']]


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/