CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Multiple Selections

 



pu_nk
journeyman

Feb 2, 2001, 12:03 AM

Post #1 of 5 (171 views)
Multiple Selections Can't Post

For some reason this is just not as easy as gathering info from a form...

How do i gather the information that is submitted from a forms drop down menu with multiple selection using control, but also without using cgi.pm

If you have a cgi.pm example that would be good too but in my program i am not using it (but i can if i want to)


All i am getting right now is the last item selected on the drop down menu.




sleuth
Enthusiast

Feb 2, 2001, 12:13 AM

Post #2 of 5 (168 views)
Re: Multiple Selections [In reply to] Can't Post

 I've just written a resume builder recently and I allowed multiple selections of cities in the same type of form menu, what I did was use this sub,

sub parse_form {
my (@pairs, %in);
my ($buffer, $pair, $name, $value);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
print "You cant run this script from telnet/shell.";
exit;
}

PAIR: foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

($value eq "---") and next PAIR;
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);
}
return %in;
}

Then using

$in{'form_menu_name'}

To capture the input. The way it came in was kind of unusual because instead of having newlines between each entry there were something like ~ or similar, all I did was convert them to newlines so i would be readable by my script later, you'd want to convert them to whatever you need.

So try that and tell me if it works.

Tony



pu_nk
journeyman

Feb 2, 2001, 12:14 AM

Post #3 of 5 (167 views)
Re: Multiple Selections [In reply to] Can't Post

Sweet.. That was a fast reply..
I will try it right now and let you know.

Thanx

Drew



pu_nk
journeyman

Feb 2, 2001, 12:26 AM

Post #4 of 5 (165 views)
Re: Multiple Selections [In reply to] Can't Post

Well the code you provided Sleuth worked great!

It did show the results like so....

test1~~test2~~test3~~test4

But in a way that is good because i need the selections separated by something so i can split it up later on.

Thanks again !

Drew





Jasmine
Administrator / Moderator

Feb 2, 2001, 8:46 AM

Post #5 of 5 (160 views)
Re: Multiple Selections [In reply to] Can't Post

A CGI.pm example is at http://forums.perlguru.com/showthreaded.pl?Board=Forum7&Number=7645


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives