Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-28-2010, 01:56 AM   PM User | #1
GamerDude3282
New to the CF scene

 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
GamerDude3282 is an unknown quantity at this point
Undefined subroutine and paramater

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:
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:

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 is offline   Reply With Quote
Old 04-28-2010, 06:46 PM   PM User | #2
GamerDude3282
New to the CF scene

 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
GamerDude3282 is an unknown quantity at this point
Anyone have any ideas, as to why param doesn't seem to be working?
GamerDude3282 is offline   Reply With Quote
Old 04-28-2010, 07:43 PM   PM User | #3
bazz
Master Coder

 
Join Date: Apr 2003
Location: in my house
Posts: 5,211
Thanks: 39
Thanked 201 Times in 197 Posts
bazz will become famous soon enoughbazz will become famous soon enough
You could use the cgi module to get the params



I hope I am not going to far with a homework help.
Code:
 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
__________________
"The day you stop learning is the day you become obsolete"! - my late Dad.

Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
Useful MySQL resource
Useful MySQL link
bazz is offline   Reply With Quote
Old 04-28-2010, 07:46 PM   PM User | #4
bazz
Master Coder

 
Join Date: Apr 2003
Location: in my house
Posts: 5,211
Thanks: 39
Thanked 201 Times in 197 Posts
bazz will become famous soon enoughbazz will become famous soon enough
Quote:
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:
Code:
if ($mailTo and $mailFrom and $subjectLine and $message)
OR

Code:
unless (!$mailTo || !$mailFrom || !$subjectLine  || !$message)
hth

bazz
__________________
"The day you stop learning is the day you become obsolete"! - my late Dad.

Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
Useful MySQL resource
Useful MySQL link
bazz is offline   Reply With Quote
Old 04-28-2010, 08:30 PM   PM User | #5
GamerDude3282
New to the CF scene

 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
GamerDude3282 is an unknown quantity at this point
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.
GamerDude3282 is offline   Reply With Quote
Old 04-28-2010, 10:35 PM   PM User | #6
bazz
Master Coder

 
Join Date: Apr 2003
Location: in my house
Posts: 5,211
Thanks: 39
Thanked 201 Times in 197 Posts
bazz will become famous soon enoughbazz will become famous soon enough
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
__________________
"The day you stop learning is the day you become obsolete"! - my late Dad.

Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
Useful MySQL resource
Useful MySQL link
bazz is offline   Reply With Quote
Old 04-28-2010, 11:55 PM   PM User | #7
GamerDude3282
New to the CF scene

 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
GamerDude3282 is an unknown quantity at this point
This is very true, also I got it working.

Thanks again!
GamerDude3282 is offline   Reply With Quote
Reply

Bookmarks

Tags
cgi, param, perl, problems, undefined

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:28 AM.


Advertisement
Log in to turn off these ads.