
fox
Novice
Jul 3, 2003, 6:54 AM
Post #2 of 18
(1053 views)
|
|
Re: [Huffy] Passing Data from HTML to PERL
[In reply to]
|
Can't Post
|
|
Start your cgi with: 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; } %in =&parse_form; And to access any form field passed to the script. Use $in{"fieldName"}
(This post was edited by fox on Jul 3, 2003, 6:28 PM)
|