homepage Welcome to WebmasterWorld Guest from 54.161.185.244
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Global symbol "%Form" requires explicit package name in formmail.pl
JeffOstroff

5+ Year Member



 
Msg#: 4322366 posted 3:22 am on Jun 6, 2011 (gmt 0)

I'm using Captcha for my email form on my site with the exact code Google tells you to add to the FormMail.PL file on my server in irder to make Captcha show up on my form.

My formMail.pl script was running perfectly for me until I added the captcha stuff tonight, now I get Internal Error 500 when I run the email form and submit my response to the cpatha challenge.
The script error log on my server shows these errors:

Global symbol "%Form" requires explicit package name at /usr/home/laude5/www/cgi-bin/FormMail.pl line 118.
Global symbol "%Form" requires explicit package name at /usr/home/laude5/www/cgi-bin/FormMail.pl line 119.
Global symbol "%Config" requires explicit package name at /usr/home/laude5/www/cgi-bin/FormMail.pl line 135.
Global symbol "%Config" requires explicit package name at /usr/home/laude5/www/cgi-bin/FormMail.pl line 136.
BEGIN not safe after errors--compilation aborted at /usr/home/laude5/www/cgi-bin/FormMail.pl line 138.


Here is a snipet of the code that The server is whining about, this is some of the lines that Google tells you to add to Formmail.pl for captcha, and the lines 118 and 119 mentioned in th elog file output above are the 2 lines shown below that start off with the words challenge and response:

##############################################################################
# Check the CAPTCHA response via the reCAPTCHA service.
sub check_captcha {

my $ua = LWP::UserAgent->new();
my $result=$ua->post(
'http://www.google.com/recaptcha/api/verify',
{
privatekey => 'I blocked this number out for security reasons',
remoteip => $ENV{'REMOTE_ADDR'},
challenge => $Form{'recaptcha_challenge_field'},
response => $Form{'recaptcha_response_field'}
});

if ( $result->is_success && $result->content =~ /^true/) {
return;
} else {
&error('captcha_failed');
}
}
# NOTE rev1.91: This function is no longer intended to stop abuse, that
#
# functionality is now embedded in the checks made on @recipients and the
#
# recipient form field. #


Can't figure out what's wrong. MY FOrmMail.pl is set to strict, but shouldn't Captcha code provided by Google be ok with it?

 

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4322366 posted 6:36 am on Jun 6, 2011 (gmt 0)

I guess %Form and %Config are defined with "my" in your script, but are not passed to the sub routine, thus it complains. Either make those variables global ("our %Form" or "use vars qw/%Form/") or pass them into the sub.

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4322366 posted 11:18 am on Jun 6, 2011 (gmt 0)

http://perldoc.perl.org/functions/my.html [perldoc.perl.org]:
A my declares the listed variables to be local (lexically) to the enclosing block, file, or eval.

JeffOstroff

5+ Year Member



 
Msg#: 4322366 posted 1:14 pm on Jun 6, 2011 (gmt 0)

Still a bit confused as to why the error file is calling it "%Form" and "%config", and I can't find variables with that exact name in my FormMail.pl file so I don't know where I am supposed to change anything. Let me set the stage of what is supposed to happen.

I have a simple contact us form on my html page. Google gives me this very simple Java script code to place on my html form page to call the captcha image from the Google servers:



<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=my-globalkeygoes-here"></script><noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=my-globalkeygoes-here" height="300" width="500" frameborder="0"></iframe>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"></noscript>



Next I have below the FULL code that Google says to place into FormMail.pl, but they don't mention anything about setting any other variables to global or anything. This time I listed below for you the full set of code Google tells you put into Formmail.pl below. The 4 lines that my error log are complaining about, I have bolded below:


######################################################

use LWP::UserAgent;

# Check Required Fields
&check_required;

# Check the captcha challenge and response.
&check_captcha;

# Send E-Mail
&send_mail;

# Return HTML Page or Redirect User
&return_html;

##############################################################################
# Check the CAPTCHA response via the reCAPTCHA service.
sub check_captcha {

my $ua = LWP::UserAgent->new();
my $result=$ua->post(
'http://www.google.com/recaptcha/api/verify',
{
privatekey => 'my-privatekeygoes-here',
remoteip => $ENV{'REMOTE_ADDR'},
challenge => $Form{'recaptcha_challenge_field'},
response => $Form{'recaptcha_response_field'}

});

if ( $result->is_success && $result->content =~ /^true/) {
return;
} else {
&error('captcha_failed');
}
}
# NOTE rev1.91: This function is no longer intended to stop abuse, that #
# functionality is now embedded in the checks made on @recipients and the #
# recipient form field. #


#THIS IS ERROR FUNCTIONALITY CODE FOR CAPTCHA:

if ($Config{'missing_fields_redirect'}) {
print "Location: " . &clean_html($Config{'missing_fields_redirect'}) . "\n\n";
}

}
elsif ($error eq 'captcha_failed') {
print <<"(END ERROR HTML)";
Content-type: text/html

<html>
<head>
<title>Error: Captcha Check Failed</title>
</head>
<body bgcolor=#FFFFFF text=#000000>
<center>
<table border=0 width=600 bgcolor=#9C9C9C>
<tr><th><font size=+2>Error: Captcha Check Failed</font></th></tr%gt;
</table>
<table border=0 width=600 bgcolor=#CFCFCF>
<tr><td>The Captcha response of the form you submitted did not match the challenge.
Please check the form and make sure that your response matches the challenge in the captcha image.
You can use the browser back button to return to the form.
</center>
</td></tr>
</table>
</center>
</body>
</html>
(END ERROR HTML)
} else {
foreach $missing_field (@error_fields) {
$missing_field_list .= "<li>" . &clean_html($missing_field) . "\n";
.
.
.
</html>
(END ERROR HTML)
}
exit;
}

########### END OF CAPTCHA RELATED CODE##########


So that's all the code they supplied. I'm not sure what I am supposed to do. The other thing is, their code calls this Perl module LWP::UserAgent and I don't know for sure where it should be on my server, (CGI-BIN?), just want to make sure it's there and executing properly.

What do I do now? Frustrating!

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4322366 posted 10:15 pm on Jun 6, 2011 (gmt 0)

It'd be great if you could refrain from making that much text bold.

Maybe that $Form{'recaptcha_challenge_field'} is just a placeholder for "however you read input values submitted by the browser", so it could be $CGI->param('recaptcha_challenge_field') or something else, depending on which script you are using.

the %Config-stuff seems not to be related to the captcha itself but rather wether all fields have been filled out.

Where did you get that FormMail-script from? Are you sure that google's info are for that specific script? Many scripts that send emails when a form is submitted are named formmail.pl, but that doesn't mean they're compatible with each other.

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4322366 posted 11:50 pm on Jun 6, 2011 (gmt 0)

assuming you are using MSA FormMail.pl, the %Config and %Form hashes should be defined in sub parse_form.

also note that in google's recaptcha/formmail documentation they don't provide "FULL code", but rather specify additional code.
Using reCAPTCHA with FormMail - reCAPTCHA - Google Code:
http://code.google.com/apis/recaptcha/docs/formmail.html [code.google.com]

JeffOstroff

5+ Year Member



 
Msg#: 4322366 posted 2:53 am on Jun 7, 2011 (gmt 0)

Yes, phranque, that link you posted above is exactly where I originally got that captcha code off Google's web site, and implemented exactly as they show you on that page, adding those sections directly to my already working FormMail.pl file. Google's web site said it was for FormMail.pl.

Here is more info on the headers identifying the orignation of my FormMail.pl:

# nms Formmail
Version 3.14c1 #
# Copyright 2001 London Perl Mongers
All rights reserved #
# Created 11/11/01
Last Modified 08/11/04 #
# Matt's Script Archive: [scriptarchive.com...] #
##############################################################################
# nms Formmail has been created as a drop in replacement for the FormMail
#
# found at Matt's Script Archive. Both the original and nms versions of this
#
# script can be found at the above URL.
Support for nms Formmail is #
# available through: nms-cgi-Support@lists.sourceforge.net #
##############################################################################
#
# NMS FormMail Version 3.14c1




The formmail.pl code is a standard across numerous companies. It was supplied by my web host NTT/Verio, it's generated automatically, and you just change a few items like where the mail gets forwarded to, etc. The formmail code was already working perfectly for me for a year, but this month I started receiving tons of spam every hour from loser drug sites, so I decided to add the reCaptcha code from Google, as their link above mentions.

So what do I do from here?

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4322366 posted 4:51 am on Jun 7, 2011 (gmt 0)

you add the lines beginning with plus signs as described in the recaptcha documentation supplied by google and leave the rest as is.

also it looks like the FormMail you are using is the nms version while the recaptcha doc appears to be referring to the MSA version.

JeffOstroff

5+ Year Member



 
Msg#: 4322366 posted 1:13 pm on Jun 7, 2011 (gmt 0)

Yes, that is exactly what I did, I removed the + signs. But also the Google page does not specify that it is the MSA version of FormMail, so how do you know that is what they are implying? And if their code is for the MSA version, what should I do to my NMS version to make it work? If this is Perl script, it should work the same in both versions, unless I need to declare something or set some variable somewhere.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved