1
votes

in my perl CGI dynamic website i combine Apache URL rewriting and form posted data.

Apache

Alias "/test" "C:/Users/Fred/workspace/test"
<Directory "/Users/Fred/workspace/test/">
Allow from 127.0.0.1
Options +ExecCGI
RewriteEngine On
RewriteBase /test/
RewriteRule ^$ cgi-bin/index.pl [L]
RewriteRule ^fred/(.+)$ cgi-bin/fred.pl?data=$1 [L]
</Directory>

HTML form

<form action="fred/1234" method="post">
  <input type="text" name="text" value="ABCD" />
  <input type="submit" />
</form>  

The following perl code will display an empty value for 'data' because cgi->param('data') returns nothing although $ENV{'QUERY_STRING'} contains 'data=1234' :

my $cgi = CGI->new;
print $cgi->header();

print Dumper($ENV{'QUERY_STRING'});

my $data = $cgi->param('data');
my $text = $cgi->param('text');

print "data=$data<br/>";
print "text=$text<br/>";

Any idea why 'data' variable is not included in CGI parameters ?

Thanks.

FRED

1

1 Answers

1
votes

You're POSTing the form in your example, which means the form data is available in the request body. The query string is only used for the GET method. You cannot mix POST and GET.