Solved

Looping Through Dynamic Form Fields

Posted on 2010-09-13
9
592 Views
Last Modified: 2012-06-21
I am working on a form that initially has some fields, but the user can also add more dynamically.
All fields follow the name var#index# and price#index# where #index# is the number of lines in the form so far.  Also form fields are always 1 var field and 1 price field.  The extra fields are added via a jQuery function.
So now I need to process the form once submitted.  Is there a way I could loop over the fields to get the values?

Let me know if you need any code.

PS there is also one other field in the form called title.
PPS the form is in an application driven by the FW/1 framework so I don't have the form scope.  Instead I have the Request Context (RC scope) which essentially contains the request scope.
0
Comment
Question by:paldie
  • 5
  • 4
9 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 33662490
you need some kinda hidden variable on the form, so every time the Jquery add a row it adds 1 to that hidden variable. And then you will simply do the loop through that variable.

ANd do

<cfset t = form["name" & ID]>
0
 

Author Comment

by:paldie
ID: 33662510
That is exactly what I need to do.  I am not sure what you are doing on that cfset, but the first part I get and then I know exactly how to process it.
0
 
LVL 19

Accepted Solution

by:
erikTsomik earned 500 total points
ID: 33662617
so if you get the first part then you know then number of iteration. From here it is simple

something like this
<cfloop index="i" from="i" to="#form.hiddenField#">


<!---do the form evalaution here---->
<cfif isDefined("form.var#i#")>
<cfset var = Evaluate("form.var#i#")>
</cfif>

</cfloop>
0
 

Author Closing Comment

by:paldie
ID: 33662653
Thanks for the help.  That was exactly what I was looking for.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 19

Expert Comment

by:erikTsomik
ID: 33662779
Also for performance do not recommend using evaluate

Use this notation

<cfset var=form["var#i#"]>

0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 33662783
thank you
0
 

Author Comment

by:paldie
ID: 33662859
Because the processing this withing FW/1 and everything is thrown into the RC struct would it be possible to call rc['var#i#']?  RC holds the form structure.
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 33662917
sure. Are you using a coldbox?
0
 

Author Comment

by:paldie
ID: 33662987
No it is FW/1 (and Transfer ORM).  It is Sean Corfield's framework, which is a great introduction into Frameworks.  It doesn't use any XML files for configuration, instead it builds views, layouts, controllers, and services  by directory structure.  Have a full E-Commerce application built on it using 4 different sub-systems (mini applications).

http://github.com/seancorfield/fw1/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now