Illinois Institute of Technology


Internet Technology Certificate 

Form Handler

A Perl CGI subroutine to translate name=value pairs from an HTML form data stream into a form usable for Perl programming. Copyright 1999 by Johnny Cison  <johnny@cisonvision.com>; used by permission.

sub TranslateForm
{
   if ($ENV{'REQUEST_METHOD'} eq 'POST')
   {
      read(STDIN, $Buffer, $ENV{'CONTENT_LENGTH'});
      @Pairs = split(/&/, $Buffer);
   }
   elsif ($ENV{'REQUEST_METHOD'} eq 'GET')
   {
      @Pairs=split(/&/, $ENV{'QUERY_STRING'});
   }

   foreach $Pair (@Pairs)
   {
      ($VariableName, $VariableValue)=split(/=/, $Pair);
      $VariableName =~ tr/+/ /;
      $VariableName =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $VariableValue =~ tr/+/ /;
      $VariableValue =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      $VariableValue =~ s/<!--(.|\n)*-->//g;

      if ($$VariableName eq '')
      { $$VariableName=$VariableValue; }
      else
      { $$VariableName .= ",$VariableValue"; }
   }
}

############################################################
# Copyright 1999 Johnny Cison <johnny@cisonvision.com>;    #
# may be reused for non-commercial purposes if accompanied #
# by this copyright statement.                             #  
# No warranty of suitability for any purpose is implied    #
# or included; all use is at your own risk.                #
############################################################

Home Search Admissions Feedback
IIT Webmaster - Last Updated December 6, 1999 by
Ray Trygstad trygstad@iit.edu