Jquery Serialize Add Field

Why should I have to deal with that in the first place? Why not just append the element to the form, then serialize it, cleaner than having to concatenate strings to the serialized form, which the dev could get wrong simply by missing an & or = for each field added. – steadweb Jan 9 '14 at 23:22. The serialize method creates a URL encoded text string by serializing form values. You can select one or more form elements (like input and/or text area), or the form element itself. The serialized values can be used in the URL query string when making an AJAX request. I want to send all the form input values using serialize and add formData too. In this case serialize won't help you, but there is a better way. Simply provide the form DOMElement to the FormData constructor. Then all the data from the form fields (including the images) will be placed in to the FormData object.

Active2 years, 10 months ago

I run serialize on a form, where on of the fields is hidden - and it's a very important field, which should be posted. Is there any way to easily serialize it through jQuery or should I write my own function?

gruszczygruszczy
28.4k22 gold badges107 silver badges157 bronze badges

6 Answers

Serializedoes include all enabled input elements with a name attribute.

Josh StodolaJosh Stodola
65.7k40 gold badges172 silver badges218 bronze badges

Maybe combining the two in a single selector would work?

Jquery Serialize Add Field In Outlook

edit: I just tried the above and it worked. but, $('form').serialize(); should automatically take all inputs as others have mentioned.

Jim SchubertJim Schubert
18.6k4 gold badges49 silver badges65 bronze badges

Here's a weird variation on this problem. The hidden fields have names.

Jquery Serialize Add Field In Java

Correctly pops up a window with all of the hidden fields. But

Does not have the hidden fields. When the php script does print_r($_POST) the hidden and checkboxes are mising

BobBob

Just ran into this problem myself, and hacked out a solution.

The problem has to do with the way JQuery picks up hidden html information. It will not pick up the TEXT of a hidden field as its value, you must use the value= property.

To set it in JQUERY use $(field).val(yourvalue);

KilleRKilleR

you should add name to all elements for serialize function to work properly

Cengiz ÖnkalCengiz Önkal

I had this problem as well. Out of habit I close my input fields with />. I found that hidden input does not work when closed this way.

does not work.

does work.

Mark TebaultMark Tebault

Not the answer you're looking for? Browse other questions tagged jqueryserialization or ask your own question.

Active3 months ago

I am trying to submit my form in AJAX, so I have to serialize() the data. But I am using fckEditor and jQuery doesn't know how to deal with it, so after the serialization, I am trying to manually modify the value, but no luck so far... any ideas

pnuts
51k8 gold badges65 silver badges105 bronze badges
BluemagicaBluemagica
2,38911 gold badges40 silver badges66 bronze badges
Serialize

3 Answers

serialize returns a URL-encoded string containing the form fields. If you need to append to it, you do so using the standard URL-encoded string rules, e.g.:

(The above assumes there will always be one value in values after the serialize call; if that's not necessarily true, determine whether to use & based on whether values is empty before you add to it.)

Alternately, if you like, you can use serializeArray and then add to the array and use jQuery.param to turn the result into a query string, but that seems a long way 'round:

Update: In a comment added later you said:

The problem is, there is some default values being set in the 'content' key during the serilization process, so I can't just attach a new value, I have to update the one already in it'

That changes things. It's a pain to look for content within the URL-encoded string, so I'd go with the array:

You'd probably want to make this a reusable function.

T.J. CrowderT.J. Crowder
740k136 gold badges1341 silver badges1407 bronze badges

Here is a full jquery plugin based on @T.J's answer. You can call

Which will replace or add the param 'foo' with value 'bar' (or any other param you add in the object)

jQuery plugin :

Cyril Duchon-DorisCyril Duchon-Doris
5,8815 gold badges29 silver badges80 bronze badges

With JQuery version now.U can use this instead one for editing current submitted value (the shortest one)

Yanuarizal KurniaYanuarizal Kurnia

Not the answer you're looking for? Browse other questions tagged jqueryserializationfckeditor or ask your own question.