...

View Full Version : Undefined subroutine and paramater



GamerDude3282
04-28-2010, 01:56 AM
I'm just starting out with CGI..

And my assignment was to create an e-mail form utilizing CGI and perl and forms.

I keep getting this error: Undefined subroutine &main:: param called at ./a16.cgi line 26

I've looked at it for several hours, and still can't figure out why it won't work. My instructor also couldn't figure out why.

I don't think its recognizing "param" as a function, your help would be very much appreciated!

CGI code:


#!/usr/bin/perl -w

use warnings;
use strict;
use CGI::Carp qw/fatalsToBrowser/;
use Mail::Sendmail;
print "Content-Type: text/html\n\n";

# use your address here instead of me@somewhere.com for testing purposes!
my $mailTo = param('to');

# use your address here instead of me@nowhere.com for testing
my $mailFrom = param('from'); # in your CGI, this will be val of param()

my $subjectLine = param('subject'); # in your CGI, this will be val of param()
my $message = param('message'); # in your CGI, this will be val of param()

if ($mailTo eq "")
{
print "Please enter your e-mail address!"
}

if ($mailFrom eq "")
{
print "<br/>Please enter recipient's e-mail address!"
}

if ($subjectLine eq "")
{
print "<br/>Please enter subject!"
}

if ($message eq "")
{
print "<br/>Please enter a message!"
}

#if ($mailTo or $mailFrom or $subjectLine or $message eq "")
#{
#print a ({ -href => "javascript:history.back();" }, "Go back and fill in everything!");
#}

my %mail = ( To => $mailTo,
From => $mailFrom,
Subject => $subjectLine,
Message => $message, # must be a string, not an array
'Content-Type' => 'text/plain'
);

if ($mailTo and $mailFrom and $subjectLine and $message ne "")
{
(sendmail %mail ) and

print "Successfully sent mail to $mailTo. Check your box!\n";
}

Form code:


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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Mail-Me Program</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="my.css" />

</head>


<body>

<form name="mailme" action="a16.cgi" method="get">

Enter your e-mail address:
<br/><input type="text" name="from" />

<br/>Enter recipient's e-mail:
<br/><input type="text" name="to" />

<br/>Enter a subject:
<br/><input type="text" name="subject" />

<br/>Enter your message:
<br/><textarea name= "message" rows="10" cols="50"></textarea>

<br/><input type="submit" value="Submit!" />

<input type="reset" value="Reset!" />

</form>

<p><a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10-blue"
alt="Valid XHTML 1.0 Tansitional" height="31" width="88" /></a>
</p>



</body>


</html>

GamerDude3282
04-28-2010, 06:46 PM
Anyone have any ideas, as to why param doesn't seem to be working?

bazz
04-28-2010, 07:43 PM
You could use the cgi module to get the params



I hope I am not going to far with a homework help.


use CGI;
my $cgi = new CGI;
my %params = $cgi->Vars;


then loop through the hash %params, to get the submitted values you need and to clean them of potentially bad data.

bazz

bazz
04-28-2010, 07:46 PM
if ($mailTo and $mailFrom and $subjectLine and $message ne "")


is that doing what you think it is? I reckon you want to ensure all form entries are filled. if so, you can do it like this:


if ($mailTo and $mailFrom and $subjectLine and $message)


OR



unless (!$mailTo || !$mailFrom || !$subjectLine || !$message)


hth

bazz

GamerDude3282
04-28-2010, 08:30 PM
Thanks a lot! l will give it a try!

Also your not going to far with homework help, as my teacher couldn't figure my problem out either, so I didn't really have anywhere else to turn.

bazz
04-28-2010, 10:35 PM
lol. I meant going too far as per the rules of the forum.

It is unfortunate that tutors have such limitations but, as most coders here seem to accept, it is very difficult to stay on top of a subject, when you are teaching it more than staying up to date.


bazz

GamerDude3282
04-28-2010, 11:55 PM
This is very true, also I got it working.

Thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum