Hi all !
I am writing a perl cgi script. I have the form also to submit the data
to the script. Whenever I call the script from the form instead of the
result of the script all I get is the script itself in the browser. It
is really a very basic structure which i have.
In the options for the directory on my server I have included ExecCGI
and also the script has read/execute access for anybody

The HTML file:

<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<FORM ACTION="http://jbn.bio.buffalo.edu/web/test.cgi"; METHOD=POST>
<TEXTAREA NAME="val1" ROWS=5 COLS=50>Default</TEXTAREA>
<TEXTAREA NAME="val2" ROWS=5 COLS=50>Default</TEXTAREA>
<INPUT TYPE="submit" VALUE="Submit">
<INPUT TYPE="reset" VALUE="Start over">
</FORM>
</BODY
</HTML>

The cgi script:
#! /usr/bin/perl

print "Content-type: text/html\n\n";

&ReadParse;

print "<title> The Response</title>";
print "Here is the form data:<ul>";

foreach $key (keys %in) {
        print "<li>$key: $in{$key}";
}

print "and here are all the environment variables:<ul>";
foreach $key (keys %ENV) {
        print "<li>$key: $ENV{$key}";
}
print "</ul>";

sub ReadParse {
        local (*in) = @_ if @_;
        local ($i,$key,$val);
        if( $ENV{'REQUEST_METHOD'} eq "GET" ) {
                $in = $ENV{'QUERY_STRING'};
        }
        elseif( $ENV{'REQUEST_METHOD'} eq "POST") {
                read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
        }
        else {
                $in = ( grep( !/^-/, @ARGV)) [0];
                $in =~ s/\\&/&/g;
        }

        @in = split(/&/,$in);

        foreach $i (0 .. $#in) {
                #Convert plus to spaces
                $in[$i] =~ s/\+/ /g;
                
                #Split into key and value
                ($key,$val) = split(/=/,$in[$i],2); #splits on the first =
                
                #Converts %XX from hex numbers to alphanueric
                $key =~ s/%(..)/pack("c",hex($1))/ge;
                $val =~ s/%(..)/pack("c",hex($1))/ge;
                $in{$key} .="\0" if( defined($in{$key}));
                $in{$key} .= $val;
        }
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to