PruitIgoe
PruitIgoe

Reputation: 6384

jquery serialize question

Is there something else I can use on a form to get all the elements and their values that won't put them into URL notation? Or is there a quick way to clean up the string returned?

I'm getting this returned:

filePath=afile.doc&fileTitle=A+File&fileDescription=This+should+be+first+in+an+asc+sort%2C+last+in+a+desc

and would need to clean up the URL stuff for a database submission - (the "+" symbol nad %2C (comma).

Is there a simple way to reverse standard URL-encoded notation?

Upvotes: 4

Views: 3540

Answers (3)

mcgrailm
mcgrailm

Reputation: 17640

if you use post instead of query you can name your elements into an array

<input type="hidden" name="block[369][filepath]" value="somepath"/>
<input type="hidden" name="block[369][title]" value="somefile.gif"/>
<input type="hidden" name="block[369][description]" value="imagefile"/>

I'm kind of assuming allot here but this is how I put things into an array for php parsing so I don't have to rely on jQuery to serialize

just an idea

Upvotes: 1

T.J. Crowder
T.J. Crowder

Reputation: 1074028

Is there something else I can use on a form to get all the elements and their values that won't put them into URL notation?

Yes, you can use jQuery's serializeArray, which will "...Encode a set of form elements as an array of names and values." This would be best, as you avoid doing the encoding in the first place (I take it you want to work with the unencoded version of the values).

Example:

var a, index, entry;
a = $("#theForm").serializeArray();
for (index = 0; index < a.length; ++index) {
  entry = a[index];
  display("a[" + index + "]: " + entry.name + "=" + entry.value);
}

Live copy

Is there a simple way to reverse standard URL-encoded notation?

Yes. Individual encoded values can be decoded using decodeURIComponent; a full string of fields can be decoded with decodeURI.

Upvotes: 9

omabena
omabena

Reputation: 3581

I think you could decode your URL with your server side language, in php for example string urldecode ( string $str );

Upvotes: 0

Related Questions