2 Replies - 1794 Views - Last Post: 12 August 2019 - 05:28 PM Rate Topic: -----

#1 frankpmjr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-August 19

Dynamic Form fields

Posted 12 August 2019 - 07:28 AM

Hello,
I am returning to CF after a very long hiatus (about 10 years) and am struggling to figure out how to do something. I have a form with a variable number of html inputs so there may be 4 of these <input type="textbox" name="textbox1"> except of course the others would be textbox2, textbox3 etc. there may be 10 of those as well. The point is the number of textboxes are variable so I can't hardcode the input query on the action page. I need some kind way to loop through the variables so I can input them into a db table. The inputs to the db would be the values from the form (#form.textbox1#) So far I have this:
<cfloop index="i" from="1" to "#numfields#">
<cfset fieldind = "textbox"#i#
<cfquery datasource="mydatasource">
   Insert into mytable
     (Fieldname)
     VALUES
     (#fieldind#)

</cfloop>
:code:

This works in that I get a table full of the names of the fields (form.textbox1, form.textbox2 etc)

What I really need are the values from those fields not the names. I can set it up so the code looks right but unfortunately there is a layer of evaluating that I am missing.

This is kind of hard to explain for me so my apologies for the confusion. Please feel free to ask questions if you need.

Thanks

This post has been edited by modi123_1: 12 August 2019 - 08:15 AM
Reason for edit:: In the future, highlight the text that is your code and click the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: Dynamic Form fields

#2 Craig328   User is offline

  • I make this look good
  • member icon

Reputation: 2042
  • View blog
  • Posts: 3,644
  • Joined: 13-January 08

Re: Dynamic Form fields

Posted 12 August 2019 - 10:09 AM

Welcome back to CF!

What you're looking for is the old Evaluate() tag. There is a better way to do this and you can see it here:http://www.bryantwebconsulting.com/blog/index.cfm/2005/3/17/ditch_coldfusion_evaluate

Good luck!
Was This Post Helpful? 1
  • +
  • -

#3 frankpmjr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-August 19

Re: Dynamic Form fields

Posted 12 August 2019 - 05:28 PM

View Postfrankpmjr, on 12 August 2019 - 07:28 AM, said:

Hello,
I am returning to CF after a very long hiatus (about 10 years) and am struggling to figure out how to do something. I have a form with a variable number of html inputs so there may be 4 of these <input type="textbox" name="textbox1"> except of course the others would be textbox2, textbox3 etc. there may be 10 of those as well. The point is the number of textboxes are variable so I can't hardcode the input query on the action page. I need some kind way to loop through the variables so I can input them into a db table. The inputs to the db would be the values from the form (#form.textbox1#) So far I have this:
<cfloop index="i" from="1" to "#numfields#">
<cfset fieldind = "textbox"#i#
<cfquery datasource="mydatasource">
   Insert into mytable
     (Fieldname)
     VALUES
     (#fieldind#)

</cfloop>
:code:/>

This works in that I get a table full of the names of the fields (form.textbox1, form.textbox2 etc)

What I really need are the values from those fields not the names. I can set it up so the code looks right but unfortunately there is a layer of evaluating that I am missing.

This is kind of hard to explain for me so my apologies for the confusion. Please feel free to ask questions if you need.

Thanks


Thank you for the help (both of you) the Evaluate() function worked!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1