PDA

View Full Version : Problems passing information from a Web form to a Perl script


Talonsrest
08-24-2006, 11:19 PM
I am building a form that allows the user to select several options they would like when we order them a server and then the form will take the information and send it to our ticketing system. I have a small test form built and a perl script to send the information. Both pieces work individually. If I take the action attribute out of the form tag and submit the form, I can see the form is submitting the correct information. I can then copy and paste it as the arguments to the command line for a perl script and that sends the mail beautifully.

The problem is that when I click send to call the script from the page, the values are not passed to the script. I created a test script to just print any arguments to a file and it just creates an empty file.

I've tried single and double quotes on the action attribute value. I've tried putting the script in the same directory as the page file.

Any help would be appreciated. This is being tested on a Windows XP system with IIS installed.

The code for the page and the script are as follows.

Perl Script

#! /usr/local/bin/perl -w

use Net::SMTP;
use CGI qw(:standard);

$subject = "Subject: New Server Request";
$newline = "\n";
$requester = param('name'). " would like to request a server\n";
$ramsize = "Ram = ". param('ram');
$drivesize = "\nHard Drive =". param('harddrive');

@message = ($subject, $newline, $requester, $ramsize, $drivesize);

$smtp = Net::SMTP->new("xxxxx.xxxx.xxxx.com");

$smtp->mail("username\@xxxx.xxxx.com");
$smtp->to("ticketingsystem\@xxxx.xxxx.com");


$smtp->data(@message);

$smtp->quit;

Web Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">

<html>
<head><title>Test Server Form</title></head>
<body>
<form action ="/cgi-bin/mailer.pl" method="get" >
<p>
<h4>Name:</h4>
<input name="name" class="required" />
<h4>Memory</h4>
</p>
<p>
<SELECT name="ram" class="required">
<option selected value=128>128 Meg</option>
<option value=256>256 Meg</option>
<option value=512>512 Meg</option>
<option value=1024>1 Gig</option>
</select>
</p>
<p>
Hard Drive:
<select name="harddrive" class="required">
<option selected value=18>18 Gig</option>
<option value=40>40 Gig</option>
<option value=128>80 Gig</option>
<option value=128>120 Gig</option>
</select>
</p>
<p>
<input type="submit" value="Send" />
</p>
</form>
</body>
</html>

KevinADC
08-25-2006, 04:59 AM
is this the correct shebang line?

#! /usr/local/bin/perl -w

have you checked the server error logs to seee if the script is creating any warnings or errors?

The script you posted prints nothing to the browser so it should end with a 500 error meassge being printed to the screen but it should still send the data if everything thing else is OK.

Talonsrest
08-25-2006, 05:27 PM
is this the correct shebang line?

#! /usr/local/bin/perl -w

I've run it with just #! /usr/bin/perl -w and I get the same result.


have you checked the server error logs to seee if the script is creating any warnings or errors?

No errors in the service log. In my test script, I redirected the standard error messages to a text file but nothing appears in that either.


The script you posted prints nothing to the browser so it should end with a 500 error meassge being printed to the screen but it should still send the data if everything thing else is OK.

I would have suspected getting the 500 error message as well but that isn't happening. When I run it with my test script that just prints the arguments to a text file, the page flickers, the output file is created but there is nothing in it. If I feed the test script test data at a command line, it works just fine.

I'm including my "print arguments to file" test script here as well. Maybe there is something in common someone will see with it here as well.

#! /usr/bin/perl -w

use Net::SMTP;
use CGI qw(:standard);

open (ARGUMENTS, '>c:/temp/argu.txt');
open STDERR, ">c:/temp/err.txt";

print ARGUMENTS @ARGV;
print ARGUMENTS "\n";

foreach $key (param()) {
print ARGUMENTS "$key has the value of ", param($key), "\n";
}

close ARGUMENTS;