Click to See Complete Forum and Search --> : Getting form values


Jona
03-17-2003, 05:48 PM
How do I get the value of a textfield on the previous page submitted by the POST method?

Is it something like...

my $tekstValue = ENV{'textBoxName'}

I don't know how to do it. Please help me. Thanks.

jeffmott
03-17-2003, 10:05 PM
use CGI qw{:cgi};

my $value = param('textBoxName');

Jona
03-19-2003, 12:15 AM
Thanks! I'll try that!!

Nedals
03-19-2003, 12:22 AM
Jeff, I've traditionally used this

use CGI;
my $q = new CGI;

my $value = $q->param('textBoxName');
Is there a preference?
Does one vs the other have a more general purpose usage?

DaiWelsh
03-19-2003, 10:04 AM
You are using the object oriented version of the syntax, whereas jeff is using the 'traditional' syntax. I dont think there is any fundamental difference between the functionality available one way or the other, just whether you are familiar with OO notation or not I guess.

Jona
03-19-2003, 03:42 PM
It says I need the CGI.pm module! Where do I get that? The error is on line three. @INC contains ./lib /site_perl is part of the error. Here's the whole script:

#!/usr/local/bin/perl

use CGI qw{:cgi};

my $name = param('Name');
my $email = param('Email');

if($ENV{'Request_Method'} eq 'GET') {
print <<EOF;
Content-Type: text/html\n\n
<h1>You cannot use the GET method for this script.</h1>
EOF
}
else {
print <<EOF;
Content-Type: text/html\n\n
Name: <b>$name</b>
Email: <b>$email</b>
EOF
}

My question is how to I add the CGI.pm module? And is this script insecure or incorrect at this point?

Many thanks!!

jeffmott
03-19-2003, 06:52 PM
I dont think there is any fundamental difference between the functionality available one way or the otherActually, in larger modules using object oriented code actually yields better performance than the procedural style. However, Stein made CGI.pm a little funky by making it _both_ object oriented and procedural. As a result of added code to make that work the oo style is actually a little slower with that module.

It says I need the CGI.pm module!It should be a part of the standard Perl distribution. But based on what @INC contains (this is the array that holds the paths to be searched for imported files) it looks like the path for the Perl libraries are not being checked. Add this:use lib '/usr/local/bin/perl/lib';If that doesn't work then download it from http://search.cpan.org/CPAN/authors/id/L/LD/LDS/CGI.pm-2.91.tar.gz and put it in ./lib (relative to the script calling it).

And is this script insecure or incorrect at this point?You can (and should) use the -T switch to enabled taint mode (this enables a set of special security checks done by Perl). But a couple fixes I see off hand, 'Request_Method' as a key value in the ENV hash should be all uppercase, $ENV{REQUEST_METHOD}. And also, since the CGI module can handle both GET and POST requests there is no need for this check at all.

Jona
03-19-2003, 11:11 PM
Yah, I'll probably have to upload it. I get this error:

Can't locate CGI.pm in @INC (@INC contains: . /lib /site_perl) at qSignup.pl line 3.
BEGIN failed--compilation aborted at qSignup.pl line 3.

In which folder would I upload the module? The CGI-bin folder?

jeffmott
03-19-2003, 11:29 PM
It should go in the 'lib' directory, and the lib directory should be in the same path as the script. So relative to the script the path would be ./lib, which is already in the @INC array.

Jona
03-19-2003, 11:54 PM
So that would just be the main folder of site.com/ instead of site.com/lib ?

jeffmott
03-20-2003, 10:32 AM
No, relative to the script. If the script is in /cgi-bin/yourscript then the module goes in /cgi-bin/yourscript/lib. If the script is in /cgi-bin then the module goes in /cgi-bin/lib.

Jona
03-20-2003, 12:02 PM
Okay. I see. Let me try that. Thanks a lot for your help!!

Jona
03-20-2003, 08:43 PM
Now I get this error:

Can't locate CGI/Util.pm in @INC (@INC contains: . /lib /site_perl) at /lib/CGI.pm line 27.
BEGIN failed--compilation aborted at /lib/CGI.pm line 27.
BEGIN failed--compilation aborted at qSignup.pl line 3.

This is very agrivating! Here's what my setup is like:

site.com/cgi-bin/

cgi-bin contains: qSignup.pl
cgi-bin contains: Util.pm

site.com/cgi-bin/lib/

lib contains: CGI.pm
lib contains: Util.pm

site.com/cgi-bin/lib/cgi/

cgi contains: Util.pm


What do I need to do to get it to work? This stupid host! They don't even have the Perl modules installed!!

jeffmott
03-23-2003, 06:23 PM
Util.pm will have to go into site.com/cgi-bin/lib/CGI/Util.pm

Jona
03-25-2003, 04:31 PM
I hate this host!

I am getting a new host. The script will work, but every time I add another module (after taking 30 minutes to find the module on another computer, put it on a floppy, and bring it back to this one) it says I'm missing a different one and I have to create another folder to put it in!

I'm getting a new host. Thanks for your patience, Jeff. Constant.pm is missing in @INC this time, but I'm just going to forget the whole darn thing! It's off to a new host...

Nedals
03-25-2003, 06:22 PM
Programming = fun! :D

Actually, once you get this BS stuff solved, you're really going to enjoy Perl.

Jona
03-25-2003, 06:49 PM
Learning Perl isn't my problem. As the FAQ at perldoc.com says, "Perl doesn't require a steep learning curve." Programming = fun, but configuring Perl on a Web server when is should already be configured is not. :)