Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    New to the CF scene
    Join Date
    May 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone have any ideas, as to why param doesn't seem to be working?

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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

  • #4
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is very true, also I got it working.

    Thanks again!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •