htmlformatting.cgi

 


#!/usr/bin/perl

@pairs = split(/&/, $ENV{'QUERY_STRING'});

foreach $pair (@pairs)
{
    ($key, $value) = split (/=/, $pair);
    $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;
    $value =~s/<!--(.|\n)*-->//g;

    if ($formdata{$key})
    {
        $formdata{$key} .= ", $value";
    }
    else
    {
        $formdata{$key} = $value;
    }
}



print "Content-type: text/html\n\n";
print "<HTML><HEAD>\n<TITLE>";
print "Showing off with HTML";
print "</TITLE>\n</HEAD><BODY>\n";

print "<H2>Thanks for responding. Here's what you told us:</H2>";
print "<TABLE BORDER=3 WIDTH=60%>\n";
print "<TR><TH>Key<TH>Value\n";
foreach $key (keys %formdata){
	print "<TR><TD>$key<TD>$formdata{$key}\n";
	}
print "</TABLE>";
print "</BODY></HTML>";