Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > Passing a hash ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 1392 of 1496
Post > Topic >>

Passing a hash from a form field?

by perl4hire@[EMAIL PROTECTED] Apr 29, 2007 at 03:02 PM

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";
}
 




 5 Posts in Topic:
Passing a hash from a form field?
perl4hire@[EMAIL PROTECTE  2007-04-29 15:02:33 
Re: Passing a hash from a form field?
bills@[EMAIL PROTECTED]   2007-04-30 11:59:56 
Re: Passing a hash from a form field?
aneely@[EMAIL PROTECTED]   2007-05-01 00:03:30 
Re: Passing a hash from a form field?
mumia.w.18.spam+nospam@[E  2007-05-01 07:04:29 
Re: Passing a hash from a form field?
aneely@[EMAIL PROTECTED]   2007-05-01 20:12:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 10:22:54 CST 2008.