View Full Version : Form Input with Perl
stophon4
06-19-2004, 03:20 AM
How do you get form input with perl?
For example how would I get the result of a text box?
Also I would like like this to be the post method but if you could show me the get method too that would be helpful :rolleyes:
mlseim
06-19-2004, 04:17 AM
I think this is a pretty easy example ...
http://www.nyu.edu/webguide/form.html
I'm sure you'd find a lot more by doing your own
search with Google ... "easy perl form scripts"
stophon4
07-05-2004, 12:50 AM
OK, here is an error I am getting:
Premature end of script headers
Here is the script:
#!/usr/bin/perl
# This is the minimalist form script
# to demonstrate the use of
# the cgi-lib.pl library
require "cgi-lib.pl";
# Read in all the variables set by the form
&ReadParse(*input);
print "Content-Type: text/html\n\n";
print "You typed: " . $input{'myfield'} . "\n";
dswimboy
07-06-2004, 03:45 AM
i've always used "Content-type:" not "Content-Type". i don't know if it makes a difference, but in my mind, that would be a prematured end to headers. a capital letter where the broweser didn't expect one.
stophon4
07-07-2004, 03:00 PM
Doesn't make a difference, any one else have any insight?
mlseim
07-07-2004, 05:37 PM
I got an error also ...
original script
------------------------------------------------
[space]#!/usr/bin/perl
# This is the minimalist form script
# to demonstrate the use of
# the cgi-lib.pl library
require "cgi-lib.pl";
# Read in all the variables set by the form
&ReadParse(*input);
print "Content-Type: text/html\n\n";
print "You typed: " . $input{'myfield'} . "\n";
------------------------------------------------
Take the space out on the first line (the "shebang")... :thumbsup:
Script should look like this:
------------------------------------------------
#!/usr/bin/perl
# This is the minimalist form script
# to demonstrate the use of
# the cgi-lib.pl library
require "cgi-lib.pl";
# Read in all the variables set by the form
&ReadParse(*input);
print "Content-Type: text/html\n\n";
print "You typed: " . $input{'myfield'} . "\n";
------------------------------------------------
stophon4
07-07-2004, 05:56 PM
Still the same thing! I am using the post method if that makes a difference! Have any of you actually tested the script?
mlseim
07-07-2004, 06:51 PM
Yes,
Here's a form that sends "myfield" to your exact script.
http://www.catpin.com/myfield.htm
MattJakel
07-07-2004, 08:37 PM
When I first started using CGI on my server, I would always get the premature end to script headers error too, and I found out that it was just because I wasn't setting the permissions correctly on the file. Did you chmod it, and if you did, did you make sure it was to the correct permissions on your server (usually 755)? Another possibility is that you don't have it in the cgi-bin, that will cause this error on my server too.
Hope this helps. :)
Matt
stophon4
07-07-2004, 09:13 PM
Other scripts work fine, here is my form if it makes a difference:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Perl Form</TITLE>
</HEAD>
<BODY>
<form action='inputs.pl' method='post'>
<INPUT type='text' Name='myfield'>
<INPUT type='submit' Name='submit' Value='submit'>
</form>
</BODY>
</HTML>
mlseim
07-07-2004, 09:25 PM
<form action='inputs.pl' method='post'> :confused:
How can you have your HTML form in the same directory
as your Perl script?
Your Perl script should be in your CGI-BIN directory.
Your HTML Form webpage in your regular HTML directory.
So it would be like:
<form action='/cgi-bin/inputs.pl' method='post'>
or whatever the path is.
If you're not sure of the path, use the whole URL:
<form action='http://www.mysite.com/cgi-bin/inputs.pl' method='post'>
dswimboy
07-07-2004, 09:42 PM
first off, the script has no problems. i checked it on the command line.
second, msliem says you can't have the script and the form in the same directory. that isn't true! i only use my CGI-bin for organization reasons.
third, i have absolutly no idea what the problem is! it fails on my system too. WinXP Pro IIS 5, ActivePerl, Error: "Failed to execute script 'http://localhost/perl-scripts/read-input.pl': Win32 Error Code = 267"
MattJakel
07-07-2004, 11:12 PM
Actually, on Linux servers and some Windows servers, you DO have to put all scripts in the cgi-bin. This script runs fine on my Linux server, so I have no idea why it won't work on yours.
Matt
stophon4
07-08-2004, 01:11 AM
I have linux, and I configured my account so that cgi and perl works anywhere, other scripts work just fine in that directory, just not this script :mad:
So now what is the problem?!
MattJakel
07-08-2004, 01:19 AM
So you've written other cgi scripts that work fine in this directory and you've got permissions set to 755? If the answer to both is yes, then I have no idea what your problem is, try calling or emailing your host.
Matt
flare1028us
07-14-2004, 12:36 AM
Try using the CGI.pm param() function:
#!C:\Perl\bin\perl.exe
use CGI ':standard';
$input = param('textarea_name');
print "Content-type: text/html\n\n";
print "You typed: $input";
I think it may be something like that.
Carl
stophon4
07-15-2004, 05:16 PM
Thanks, after contacting support I found out the reason the other script wasn't working was because they had not installed the cg-lib.pl library :)
But your script works great :thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.