Solved

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

Posted on 2011-03-11
9
504 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

685 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