0

I have a scenario where I need to send form data via a GET (not a POST). I'm submitting the form to the same page as the form is on (form action="#).

The problem is that the controller for the site can't handle array data-- it looks for strings or json only. So when I have any array data from a row of text boxes that gets sent, I get a 500 error.

I am currently doing something like this:

$('#submit').on("click", function(e){
    e.preventDefault();
    $form.serialize();
    $form.submit();
})

But this doesn't get the job done. The URL params look like this:

index.php?condition%5b%5d%3dtest

How can I access the actual form data and "rewrite" the data to be a valid json string for the text box values prior to sending the form?

I could POST the data but then I'd need a different route, and I could send the form via ajax but that would be overkill.

Thanks

NOTE: I know how to serialize the data already, as is explained in my code sample. The problem is I want to replace the URL params in the default form submission with the newly serialized / json-ified versions, and the suggested duplicate question does not address this.

user101289
  • 9,888
  • 15
  • 81
  • 148
  • I'd POST it every day of the week, it's worth adding the route. If you need to get this working, I think we'll need more info about the framework you're building in and/or the code of the form and controller to give you proper recommendations. – Mikel Bitson Nov 06 '15 at 18:23
  • @MikelBitson-- I know, it's not a big deal and I'm probably wasting more time getting this working than it'd take to create a new view / route. More annoyed and curious at this point. – user101289 Nov 06 '15 at 18:25
  • The 500 error is concerning. I take it you cannot get the actual error from the host? Can you post an example of your HTML? – Twisty Nov 06 '15 at 18:27
  • Possible duplicate of [Convert form data to JavaScript object with jQuery](http://stackoverflow.com/questions/1184624/convert-form-data-to-javascript-object-with-jquery) – Hackerman Nov 06 '15 at 18:28

0 Answers0