#!/usr/bin/perl
# Perl-Programm, das die eingegebenen Formulardaten anzeigt
$| = 1;

use strict;

my %FORM = ();

# Parsing the FORM-Input
&parse_form;

# Print Results of the form
&return_html;

sub return_html 
   {
   my $key;
   print "Content-type: text/html\n\n";
   print "<HTML>\n";
   print "<TITLE>Formular-Eingabe</TITLE>\n";
   print "<BODY><H1>Formular-Check</H1>\n";
   print "Die Formulardaten lauten:<P>\n";
   print "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0>\n";
   foreach $key (sort(keys %FORM))
     {
     print "<TR><TD><B>$key: </B></TD><TD>$FORM{$key}</TD></TR>\n";
     }
  print "</TABLE>\n";
  print "<a href=\"javascript:history.back()\">Zur&uuml;ck zum Formular</a>\n";

  print "</BODY></HTML>\n";
  }


sub parse_form 
    {
    my ($buffer, @pairs, $pair, $name, $value);
    # Read in text
    if ($ENV{'REQUEST_METHOD'} eq "POST")
      {
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
      }
    else
      {
      $buffer = $ENV{'QUERY_STRING'};
      }
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs)
      {
      ($name, $value) = split(/=/, $pair);
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      if (defined $FORM{$name})
        { $FORM{$name} = $FORM{$name} . ", " . $value; }
      else
        { $FORM{$name} = $value; }
      }
    }

