Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl cgi

Status
Not open for further replies.

emat

Technical User
Sep 20, 2005
18
BE
Hi,


Im having trouble with a perl cgi.
I can get the content of the input type fields to my cgi script to process, no prolbem.
But the thing is, when I add a parameter to my script for the ACTION field, this parameter isn't transferred to my script.

Here is example code;

My main page is:

<FORM METHOD="POST" ACTION="/cgi-bin/test.pl?id=fubar" enctype="text/plain">
<B>Name :</B><INPUT TYPE="text" NAME="name" size="20">
<INPUT TYPE="submit" value="Execute">
</FORM>

my test.pl script is:

#!/usr/bin/perl -w

use strict;
use warnings;

use CGI qw:)standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

print $cgi->param('id');



$cgi->param('id') isn't defined when I use a FORM
It should print 'fubar' in this case



Anyone with tips or advice?


Thanks
 
you are sending get and post data at the same time, that isn't strictly kosher. CGI.pm can handle this but you have to edit the actual module itself, you can't just change a CGI variable and it works. Add a hidden form field and send the data that way:

Code:
<FORM METHOD="POST" ACTION="/cgi-bin/test.pl enctype="text/plain">
<B>Name :</B><INPUT TYPE="text"  NAME="name" size="20">
[b]<INPUT TYPE="hidden" name="id" value="fubar">[/b]
<INPUT TYPE="submit" value="Execute">
</FORM>
 
This should work according to the docs:

Change this:
Code:
print $cgi->param('id');

To this:

Code:
print url_param('id');

Let us know your results!

X
 
Thanks KevinADC!

Its nice getting a pat on the back from one of great ones! [wink]
 
It seems like this should be a problem too:

<FORM METHOD="POST" ACTION="/cgi-bin/test.pl?id=fubar" enctype="text/plain">

I remember a trick from the old days of not having access to Perl on free hosted websites, we'd just use mailto: as the form's action and use this enctype.

And the form data would send to the e-mail address in this form:
Code:
variable=value
var=value
var=value
...

Rather than this (with no enctype)

Code:
var=value&var=value&var=value&...

Maybe the CGI module is failing because the enctype is sending the data in in a format it's not expecting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top