sub fParse {
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);
if ($ENV{'QUERY_STRING'}) {
@getpairs = split(/&/, $ENV{'QUERY_STRING'});
push(@pairs,@getpairs);
}
} else {
print "Content-type: text/html\n\n";
print "Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%(a-fA-F0-9a-fA-F0-9)/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%(a-fA-F0-9a-fA-F0-9)/pack("C", hex($1))/eg;
$value =~s///g;
if ($fData{$key}) {
$fData{$key} .= ", $value";
} else {
$fData{$key} = $value;
}
}
}
The CGI data is stored in a hash call %fData and the fields with the multi select are comma delimited in the associated key. You can split it from there:
@meSelect = split(/\, /, $fData{$key});
Here is the same script in PERLScript running as ASP:
################################
# Gather Incoming Data Strings #
################################
$qv = $Request->QueryString($Request->QueryString->Key(0));
$fv = $qv."&".$Request->Form($Request->Form->Key(0));
@pairs = split(/\&/, $fv);
foreach $pair (@pairs){
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%(a-fA-F0-9a-fA-F0-9)/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%(a-fA-F0-9a-fA-F0-9)/pack("C", hex($1))/eg;
$value =~s///g;
if ($fData{$key}) {
$fData{$key} .= ", $value";
} else {
$fData{$key} = $value;
} }
It works. This bit of code has been floating around my library for a very long time. BTW these little subs work with both "GET" and "POST" CGI data.
-The Mage
He of the Black Perl School
In reply to Re: Multiple item selects and CGI.pm headaches!
by The Mage
in thread Multiple item selects and CGI.pm headaches!
by waswas-fng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |