PDA

View Full Version : HOW TO: nms FormMail + reCaptcha



Dizzy
08-10-2009, 12:13 AM
Hi,

I just thought I'd write a how to for setting up nms FormMail with reCaptcha as there a few posts around the place but nothing complete.

Firstly, the software used
1. nms FormMail 3.14c1 from http://nms-cgi.sourceforge.net/
2. reCaptcha from http://recaptcha.net/
3. reCaptcha 0.92 perl module from cpanel

Links with information
1. reCaptcha from http://wiki.recaptcha.net/index.php/Overview
2. Blake Girardot's steps for nms FormMail with reCaptcha from http://groups.google.com/group/recaptcha/browse_thread/thread/b4b35aa61353d485/29c47c9ea1c1b81c

Download nms FormMail and sign up to reCaptcha. Then follow Blake Girardot's steps to modifying the formmail.pl file.

To get it working on BH, you need to add the following code just under the USER CONFIGURATION SECTION:


BEGIN {
my $homedir = ( getpwuid($>) )[7];
my @user_include;
foreach my $path (@INC) {
if ( -d $homedir . '/perl' . $path ) {
push @user_include, $homedir . '/perl' . $path;
}
}
unshift @INC, @user_include;
}

and you should add the reCaptcha module with these steps
cpanel -> Perl Modules -> Search for and install Captcha::reCAPTCHA

The other tweaks in the FormMail.pl that I made are:

* Change

$address_style = 0;
to

$address_style = 1;
so the from email address is what the user wrote in the form.

* Change

print "<p><b>$name:</b> $value</p>\n";
to

print "<p><b>$name:</b><br> $value</p>\n";
so that the value appears below the name

* Change

$string =~ s|([^\w \t\r\n\-\.\,\/\:])| $eschtml_map{$1} |ge;
return $string;
to

$string =~ s|([^\w \t\r\n\-\.\,\/\:])| $eschtml_map{$1} |ge;
$string =~ s/\n/<br>/g;
return $string;
so that the carriage return is retained in a textarea field, otherwise its all in one line.

Upload the formmail.pl file to your cgi-bin/ folder and change the permissions to execute. The cpanel file manager is useful for doing this.

The other useful thing to do in your form is to add these lines just before your submit button:


<input type="hidden" name="sort" value="order:realname,email,comments" />
<input type="hidden" name="required" value="realname,email" />

This will force the user to enter a name and email address and it also removes the recaptcha challenge string from the success page and email.

I'm not an expert in this, but this is how I got it working nicely.
I've zipped up the steps from Blake Girardot in case that that page disappears.

Cheers,
Daryl