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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Data with CGI.PM

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I've never used CGI.pm. I used to have a nifty subroutine I wrote that did the functions I needed. Unfortunately, the new server I'm on doesn't like it.

What's the command to get form data from a page using CGI.pm?

My code looks like this:
###########################
use CGI;

$user = param('user');
$pass = param('pass');
###########################

Upon the line starting with "$user" the script just ends. No subsequent commands are done, and in a browser, all I get is a blank page. Any print statements before this point show up, and the script has been properly configured on the server.
 
First off, instead of:
Code:
use CGI;
Try:
Code:
use CGI qw( :all );
This will import all CGI subroutines into the main package.
If this doesn't work, check the server log files. There may be a clue as to what is going wrong in there. Also, you can run the CGI script from the command line, and see what output is generated.

Cheers, Neil :)

 
You need to create an object of type CGI in order to use the methods in the module.

use CGI qw:)common);

#create your object
my $cgi = CGI->new();

#prints your page header
print $cgi->header('text/html');

#this will give you all the values in the form
foreach my $p($cgi->param()){
$input{$p} = $cgi->param($p);
print $input{$p};
print &quot;<br>&quot;;
}

Hope these little bits help.

Mike
 
Thanks a lot to the both of you!

Just in case anyone else ever sees this, you have to &quot;combine&quot; both their answers if you're trying to extract form data into a variable.

If you use Motte's code, and want to use the &quot;$user = param('user');&quot; terms, you have to have &quot;use CGI qw( :all )&quot; above it, not common. It doesn't work with common, or at least for me it didn't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top