in reply to Re: Read JSON data from a form
in thread Read JSON data from a form

OK, the form sends stuff like this:
my $name = $q->param( 'name' ) || ''; my $email = $q->param( 'email' ) || ''; my $zip = $q->param( 'zip' ) || '';
But by serializing the data this code
var formData = $("#reply-form").serialize(); alert(formData);
adds all the values into a string. Doesnt this line: my $data = decode_json($q->param('dataString')); grabs all that the from is sending?

Replies are listed 'Best First'.
Re^3: Read JSON data from a form
by Corion (Patriarch) on Dec 29, 2013 at 19:22 UTC

    No. What part of CGI mentions the magic name dataString, or what other documentation makes you assume that?

    If you send your elements via jQuery.serialize(), you will get the elements as separate parameters in the request and can retrieve them as you already showed in your first Perl snippet.

    Your second Perl snippet makes no sense in this context.

      OK, I still need to use "$q->param(" for each value I am sending from the form, so whats the point in using JSON? Can you show any example based on this question? Thanks!

        If you want to send JSON, you need to send JSON. This means not using jQuery.serialize() but JSON.stringify(). I recommend that you find out why you want to send JSON first before trying it out. Then I recommend you actually learn about how to use JSON on both sides of the communication, and how to make sure that you are sending what you think you want to send.

        I won't write any code for you, as Google is aplenty with examples. For example this question from two years ago seems to be very close to your problem.

        But your problem seems to mainly be on the Javascript side of things, which is not very close to the topic of this site.