Lunarpages Web Hosting Forum

Author Topic: Need help with RECAPTCHA 2.0 integration for NMS FormMail  (Read 4681 times)

Offline wuhoo99

  • Newbie
  • *
  • Posts: 1
Need help with RECAPTCHA 2.0 integration for NMS FormMail
« on: November 01, 2016, 05:52:55 PM »
I'm not a Perl programmer so modifying FormMail is a bit challenging for me. I have the old RECAPTCHA 1.0 code integrated (see below) and it's been working fine for me, but now I'd like to upgrade it to 2.0 and I can't seem to find any code samples out there. All I need is the ability to verify the user's response by calling the Google API. If someone can point me in the right direction I'll greatly appreciate it.

Code: [Select]
=item check_captcha ()
Check the CAPTCHA response via the reCAPTCHA service. 
sub check_captcha {

  my ($self) = @_;
  my ($ua) = LWP::UserAgent->new();
  my ($result) = ($ua)->post(
        privatekey => '6Lfb1OwSAAAAAI30z6avl5AkyTpNzl7whsDSFFpK',
        remoteip   => $ENV{'REMOTE_ADDR'},
        challenge => $self->{Form}{'recaptcha_challenge_field'},
        response => $self->{Form}{'recaptcha_response_field'}

    if ( $result->is_success && $result->content =~ /^true/) {
        return 1;
    } else {

        if ($self->{FormConfig}{'captcha_fail_redirect'}) {
            print $self->cgi_object->redirect( $self->{FormConfig}{'captcha_fail_redirect'} );

            return 0;
        else {
            my ($self) = @_;
            $self->error_page( 'Error: Captcha Check Failed', <<END );
  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.
            return 0;

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Need help with RECAPTCHA 2.0 integration for NMS FormMail
« Reply #1 on: November 02, 2016, 02:32:57 PM »
If you have a Google Account, you should be able to sign on here and get code. I don't know if they show Perl code, but if you can find something like PHP, someone could probably figure out the equivalent Perl.

I don't use reCAPTCHA v2 for anything because I can't stand it. It never believes that I'm not a robot, and their pictures are usually ambiguous and poorly chosen. I don't want to inflict it on clients or customers!
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-