Solved

Using jquery-dynamic-form and need to submit specific field names

Posted on 2011-03-11
9
494 Views
Last Modified: 2012-05-11
form is here: http://aeronautical.com/members/form-test/

I'm using jquery-dynamic-form. It is renaming my fields which is then messing up my data submission.

What I would like to do is take the renamed fields, concatenate them together with a |  between each value and submit using the original field name.

So for instance, the first field in the first row is renamed to "parts[parts][0][part_numbers]" by jquery dynamic form. The original field name is simply part_numbers. As more parts are added I'd like to be creating a new field that will hold the concatenated value.

part_numbers=parts[parts][0][part_numbers]+"|"parts[parts][1][part_numbers]

How can I accomplish this? Right now jquery dyanmic forms is renaming any field so I can't even create a hidden input field named "part_numbers".

thanks for any assistance.
0
Comment
Question by:befidled
  • 7
  • 2
9 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 35113315
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35113316
You may use :http://api.jquery.com/serializeArray/
part_numbers = "";
$.map( $("form").serializeArray(), function(el,i) { part_numbers += ( ((i>0)?"|":"") + el.value) });

Open in new window


If you've two form and want to get the value of the fields of the second form :
part_numbers = "";
$.map( $("form:eq(1)").serializeArray(), function(el,i) { part_numbers += ( ((i>0)?"|":"") + el.value) });

Open in new window

0
 
LVL 1

Author Comment

by:befidled
ID: 35113476
But how do I then submit part_numbers? If I create a hidden inputs, the name gets replaced by the jquery-dynamic-form script.

for instance:

<input type="hidden" name="part_numbers" value="">
<input type="hidden" name="nsns" value="">
<input type="hidden" name="quantity_required" value="">
<input type="hidden" name="condition_required" value="">

gets replaced by:

<input type="hidden" name="parts[parts][1][part_numbers]" value="">
<input type="hidden" name="parts[parts][1][nsns]" value="">
<input type="hidden" name="parts[parts][1][quantity_required]" value="">
<input type="hidden" name="parts[parts][1][condition_required]" value="">
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35113524
>As more parts are added I'd like to be creating a new field that will hold the concatenated value.

If I understand you don't need the name, you need to submit the concatened value

you post it as you want, for example with a redirection :
location.href = "/path/to/ups.php?part_number" + encodeURIComponent(part_numbers);

Open in new window


jQuery.post/get/ajax/&Co :
$.post("/path/to/ups.php", { "part_number":part_number }, function() { alert("success"); });

Open in new window


the form :
$("<input name='part_number' value='" + part_number + "' />").appendTo("body");
$("form").submit();

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:befidled
ID: 35118200
I need a solution where I insert hidden inputs into my form. The form is created using Feeform for ExpressionEngine so I need to stay within the parameters of that.

Here's a quick case:

I'm using the form and I've added two additional sets of fields. So I now have fields with the following names:
parts[parts][0][part_numbers]
parts[parts][1][part_numbers]
parts[parts][2][part_numbers]

When I submit the form I need to assign the value of each of these fields to a hidden input with a name of part_number with a "|" separating each value.

So how can I do this when I submit the form?

I have this hidden input:
<input type="hidden" name="part_number" value="">

The value needs to be the concatenated values of parts[parts][0][part_numbers] through parts[parts][2][part_numbers] (or whatever the total count of my additional fields is)

And once I have the js statement to make this occur on submit, where do I put that in my javascript? Should it appear in the header on the  page with the form?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35124960
>So how can I do this when I submit the form?


part_numbers

Open in new window

$("form").submit(function() {
  part_numbers = "";
  $.map( $("form").serializeArray(), function(el,i) { part_numbers += ( ((i>0)?"|":"") + el.value) });
  $("#part_number").val( part_numbers );
});

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 35124967
forget the first code snippet of course...
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35139389
no feedback ?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35443057
Thanks for the points!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now