Difficulty with forms and dynamically named variables
Hiya, I'm trying to create a query based form which reads it's elements from a database table, then populates itself. Each input element would have be dynamically named via the DB query. Creating the form isn't so bad, but handling the insert query the other side is becoming a headache. I can't figure out how to recreate the dynamic names of the form variables and extract their data for insertion into the DB. If that makes little sense i apologise, but here is an example of what i'm trying to achieve: Query code * name=jss SELECT SUBCAT FROM JSS ORDER BY SUBCAT ASC Form code ** trcfoutput query=jsstd#SUBCAT# cfinput type=checkbox name=#SUBCAT# checked=no value=1/td/cfoutput/tr Form validation SQL input query code cfoutput query=jss cfset hello = FORM.#SUBCAT# cfif #hello# eq '1' cfquery name=insert_details INSERT INTO METADATA (ID, KEY, VALUE) VALUES ('#ID#', '#JSS_SUBCAT#','#hello#') /cfquery /cfif /cfoutput Now obviously at the moment #hello# outputs as FORM.A1 or whatever the #SUBCAT# variable held. What I need is a way of re-creating those variable names outside of the form structure, and then using these variable names to actually pull the data from the form submission. Thanks a lot for any help, H ~| ColdFusion is delivering applications solutions at at top companies around the world in government. Find out how and where now http://www.adobe.com/cfusion/showcase/index.cfm?event=finderproductID=1522loc=en_us Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287440 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Difficulty with forms and dynamically named variables
Hiya, I'm trying to create a query based form which reads it's elements from a database table, then populates itself. Each input element would have be dynamically named via the DB query. Creating the form isn't so bad, but handling the insert query the other side is becoming a headache. I can't figure out how to recreate the dynamic names of the form variables and extract their data for insertion into the DB. If that makes little sense i apologise, but here is an example of what i'm trying to achieve: (removed CF from tags so this posts) Query code * name=jss SELECT SUBCAT FROM JSS ORDER BY SUBCAT ASC Form code ** troutput query=jsstd#SUBCAT# input type=checkbox name=#SUBCAT# checked=no value=1/td/output/tr Form validation SQL input query code output query=jss cfset hello = FORM.#SUBCAT# cfif #hello# eq '1' query name=insert_details INSERT INTO METADATA (ID, KEY, VALUE) VALUES ('#ID#', '#JSS_SUBCAT#','#hello#') /query /cfif /output Now obviously at the moment #hello# outputs as FORM.A1 or whatever the #SUBCAT# variable held. What I need is a way of re-creating those variable names outside of the form structure, and then using these variable names to actually pull the data from the form submission. Thanks a lot for any help, H ~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287441 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Difficulty with forms and dynamically named variables
When you do the database update, you'll have to run the select query again and then use... cfoutput query=jss cfset theSubCat = #Evaluate(form. SUBCAT)# /cfoutput cfquery name=insert_details INSERT INTO METADATA (ID, KEY, VALUE) VALUES ('#ID#', '#theSubCat#','#hello#') /cfquery Chris Martin --- Gandy Ink Information Technology Department [EMAIL PROTECTED] (325) 949-7864 X-364 --- www.gandyink.com Hugh Fidgen wrote: Hiya, I'm trying to create a query based form which reads it's elements from a database table, then populates itself. Each input element would have be dynamically named via the DB query. Creating the form isn't so bad, but handling the insert query the other side is becoming a headache. I can't figure out how to recreate the dynamic names of the form variables and extract their data for insertion into the DB. If that makes little sense i apologise, but here is an example of what i'm trying to achieve: Query code * name=jss SELECT SUBCAT FROM JSS ORDER BY SUBCAT ASC Form code ** trcfoutput query=jsstd#SUBCAT# cfinput type=checkbox name=#SUBCAT# checked=no value=1/td/cfoutput/tr Form validation SQL input query code cfoutput query=jss cfset hello = FORM.#SUBCAT# cfif #hello# eq '1' cfquery name=insert_details INSERT INTO METADATA (ID, KEY, VALUE) VALUES ('#ID#', '#JSS_SUBCAT#','#hello#') /cfquery /cfif /cfoutput Now obviously at the moment #hello# outputs as FORM.A1 or whatever the #SUBCAT# variable held. What I need is a way of re-creating those variable names outside of the form structure, and then using these variable names to actually pull the data from the form submission. Thanks a lot for any help, H ~| Check out the new features and enhancements in the latest product release - download the What's New PDF now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287443 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Difficulty with forms and dynamically named variables
Hugh I'm trying to create a query based form which reads it's elements from a database table, then populates itself. Each input element would have be dynamically named via the DB query. Creating the form isn't so bad, but handling the insert query the other side is becoming a headache. I can't figure out how to recreate the dynamic names of the form variables and extract their data for insertion into the DB. Unless you need to insert records relating to checkboxes that aren't checked, you can just iterate over the Form structure and see what field names you've got there. Nick ~| ColdFusion is delivering applications solutions at at top companies around the world in government. Find out how and where now http://www.adobe.com/cfusion/showcase/index.cfm?event=finderproductID=1522loc=en_us Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287444 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Difficulty with forms and dynamically named variables
cfset hello = FORM[SUBCAT] ..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Hugh Fidgen [mailto:[EMAIL PROTECTED] Sent: Thursday, August 30, 2007 10:25 AM To: CF-Talk Subject: Difficulty with forms and dynamically named variables Hiya, I'm trying to create a query based form which reads it's elements from a database table, then populates itself. Each input element would have be dynamically named via the DB query. Creating the form isn't so bad, but handling the insert query the other side is becoming a headache. I can't figure out how to recreate the dynamic names of the form variables and extract their data for insertion into the DB. If that makes little sense i apologise, but here is an example of what i'm trying to achieve: (removed CF from tags so this posts) Query code * name=jss SELECT SUBCAT FROM JSS ORDER BY SUBCAT ASC Form code ** troutput query=jsstd#SUBCAT# input type=checkbox name=#SUBCAT# checked=no value=1/td/output/tr Form validation SQL input query code output query=jss cfset hello = FORM.#SUBCAT# cfif #hello# eq '1' query name=insert_details INSERT INTO METADATA (ID, KEY, VALUE) VALUES ('#ID#', '#JSS_SUBCAT#','#hello#') /query /cfif /output Now obviously at the moment #hello# outputs as FORM.A1 or whatever the #SUBCAT# variable held. What I need is a way of re-creating those variable names outside of the form structure, and then using these variable names to actually pull the data from the form submission. Thanks a lot for any help, H ~| Check out the new features and enhancements in the latest product release - download the What's New PDF now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287464 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Difficulty with forms and dynamically named variables
Chris Martin wrote: When you do the database update, you'll have to run the select query again and then use... cfoutput query=jss cfset theSubCat = #Evaluate(form. SUBCAT)# /cfoutput Evaluate is almost never, ever needed. SUBCAT is a dynamic key in the struct FORM. Happily, Coldfusion will evaluate the variable name and then working inside to out, the reference to that key in the structure. So all you have to do is #form[SUBCAT]# You can also use other operators within the structure reference. So say you had variables named form.foo_1, form.foo_2, form.foo_3 You could output those as follows: cfoutput cfloop index=i from=1 to=3 #form[foo_ i]#br / /cfloop /cfoutput Much cleaner than using Evaluate. Judah ~| ColdFusion is delivering applications solutions at at top companies around the world in government. Find out how and where now http://www.adobe.com/cfusion/showcase/index.cfm?event=finderproductID=1522loc=en_us Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287497 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4