Re: Passing a hash from a form field?
[email protected] (Bill Stephenson)
| Newsgroups | perl.beginners.cgi |
|---|---|
| Message-ID | <[email protected]> |
Take a look at the example scripts and docs... http://search.cpan.org/src/LDS/CGI.pm-3.29/examples/index.html http://search.cpan.org/src/LDS/CGI.pm-3.29/cgi_docs.html I'm pretty sure you'll find the syntax you need in those documents. Kindest Regards, -- Bill Stephenson On Apr 29, 2007, at 2:02 PM, [email protected] wrote: > I have several instances where I would like to pass a hash (or a hash > reference) in a hidden form field to a subroutine within the same > script upon submitting the form. > > So far all my attempts have failed. I'm not even sure if this is > possible. I know about passing named parameters and references but > that only seems to work if the subroutine is called directly, not due > to a form submission. Does anyone know if this is even possible, and > if so, some direction I can take? > > #! /usr/bin/perl > BEGIN > { > open (STDERR,">>$0-err.txt"); > print STDERR "\n",scalar localtime,"\n"; > } > > use strict; > use warnings; > use CGI ':standard'; > > my %Categories =( > 1 => "Exterior", > 2 => "Interior", > 3 => "Audio", > 4 => "Vehicles", > 5 => "Packages" > ); > my $form_url= url(); > > print "Content-type: text/html\n\n"; > > my $MODE=param('Mode'); > { > no strict; > $MODE="PageOne" unless $MODE; # default sub to execute > &$MODE; # else execute this > } > ############################################## > sub PageOne > { > print "<html><body>"; > > foreach my $k ( sort keys %Categories) > { > print "[$k] => $Categories{$k}<br>"; > } > > print <<EndHTML; > <form method="post" action="$form_url"> > <input type="hidden" name="Categories" value="%Categories"> > <input type="hidden" name="Mode" value="ReadCat"> > <input type="submit"> > </form> > </body> > </html> > EndHTML > } > ################################################## > sub ReadCat > { > my %Cats = param('Categories'); > print "<html><body>"; > foreach my $k (keys %Cats) > { > print "[$k] => $Cats{$k}<br>\n"; > } > print "</body></html>\n"; > } > > -- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > http://learn.perl.org/ > >