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

Dynamic Variables

Explorer ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

424

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 ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

try this way:
form[query_name['query_information_hard_coded_string']]


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

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 ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

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?

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
Explorer ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

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.

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 ,
Aug 20, 2008 Aug 20, 2008

Copy link to clipboard

Copied

If you make the query a session variable it will be available on page3. That might simplify your app.

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
Participant ,
Aug 23, 2008 Aug 23, 2008

Copy link to clipboard

Copied

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>

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
Community Expert ,
Aug 24, 2008 Aug 24, 2008

Copy link to clipboard

Copied

LATEST
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.

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