Can someone wind me up and point me in the right direction?
I'm trying to let users submit an HTML form into a file, with data intact. About 100 forms (in HTML files) were created by a couple of interns last summer, and I'd prefer to pass the form name as part of the query string (like process_form.pl?form=testform.html).
I've looked at CGI.pm (http://www.perl.com/pub/doc/manual/html/lib/CGI.html), and the tools are right there, but I can't seem to piece them together.
I know well how to fetch data from a submit, how to process it, how to email a file, etc., and I've used Perl for about two years. It's re-inserting the data back into a form that I'm stumbling over.
Here's where I'm at now, for starters.
---- Begin Perl ----
@query=split(/&/,$ENV{'QUERY_STRING'});
foreach $pair (@query) {
($key,$value)=split(/=/,$pair);
$key =~ tr/A-Z/a-z/;
$key =~ tr/+/ /;
$key =~ 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;
$query{$key}=$value;
}
read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $input);
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 =~ s/<([^>]|\n)*>//g;
$form{$name}=$value;
}
if (%form) {
restore_parameters(STDIN);
open(FORM,"$query{'form'}");
$separator=$/;
undef $/;
$query=new CGI(FORM);
close(FORM);
open(OUT,">test.html");
$query->save(OUT);
close(OUT);
print "Done.";
$/=$separator;
exit;
}
print "query(form): $query{'form'}<br>\n";
$separator=$/;
undef $/;
open(FORM,"$query{'form'}");
$form=<FORM>;
close(FORM);
print "form: $form<br>\n";
$/=$separator;
---- End Perl ----
Any suggestions?
TIA.
