Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Read JSON data from a form

by Anonymous Monk
on Dec 29, 2013 at 21:42 UTC ( [id://1068703]=note: print w/replies, xml ) Need Help??


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

use CGI->param not CGI->Vars , CGI->Vars has caveats

Replies are listed 'Best First'.
Re^3: Read JSON data from a form
by tangent (Parson) on Dec 29, 2013 at 21:54 UTC
    You are right, but I didn't know the names of the parameters at the time of writing. I can now see those from OP's reply so you could change the offending line to:
    my $in; $in->{'name'} = $q->param('name'); $in->{'email'} = $q->param('email'); # etc
      FWIW, you don't need to know the name, param without args provides the names , Vars mangles (encodes, serializes, packs, implodes) the data, its backwards compatibility for some 1993 stuff
      #!/usr/bin/perl -- use Data::Dump qw/ dd /; use CGI; my $q = CGI->new(q{a=b;a=c;d=e;f=g}); my %Vars = map { $_ => [ $q->param($_) ] } $q->param(); dd( $q ); dd( $q->Vars ); dd( \%Vars ); __END__ __END__ bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["a", "d", "f"], "escape" => 1, "param" => { a => ["b", "c"], d => ["e"], f => ["g"] }, "use_tempfile" => 1, }, "CGI") ("a", "b\0c", "d" .. "g") { a => ["b", "c"], d => ["e"], f => ["g"] } bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["a", "d", "f"], "escape" => 1, "param" => { a => ["b", "c"], d => ["e"], f => ["g"] }, "use_tempfile" => 1, }, "CGI")
      #!/usr/bin/perl -- use Data::Dump qw/ dd /; use CGI; my $q = CGI->new(q{a=b;a=c%00d;d=e;f=g}); my %Vars = map { $_ => [ $q->param($_) ] } $q->param(); dd( $q ); dd( $q->Vars ); dd( \%Vars ); __END__ bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["a", "d", "f"], "escape" => 1, "param" => { a => ["b", "c\0d"], d => ["e"], f => ["g"] }, "use_tempfile" => 1, }, "CGI") ("a", "b\0c\0d", "d" .. "g") { a => ["b", "c\0d"], d => ["e"], f => ["g"] }

        Naming things is hard :/

        #~ sub CGI::fornew { #~ sub CGI::HashVars { #~ sub CGI::VARTS { #~ sub CGI::old { #~ sub CGI::wen { #~ sub CGI::Varses { sub CGI::Wars { my $q = shift; my %Vars = map { $_ => [ $q->param($_) ] } $q->param(); return \%Vars; }
        sub CGI::AsHash { my $q = shift; my %hash; $hash{$_} = $q->param($_) for $q->param; return \%hash; }
        my $params = CGI->new->AsHash;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1068703]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found