Difference between revisions of "FormMail Captcha"

From KOP KB
Jump to: navigation, search
(Checking the Captcha)
(Captcha Failure Message)
Line 80: Line 80:
 
(END ERROR HTML)
 
(END ERROR HTML)
 
     }
 
     }
 +
</syntaxhighlight>
 +
== The Html Form Page ==
 +
<syntaxhighlight lang="html4strict">
 +
<script type="text/javascript"
 +
    src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
 +
  </script>
 +
  <noscript>
 +
    <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
 +
        height="300" width="500" frameborder="0"></iframe>
 +
 +
    <textarea name="recaptcha_challenge_field" rows="3" cols="40">
 +
    </textarea><br>
 +
    <input type="hidden" name="recaptcha_response_field"
 +
        value="manual_challenge">
 +
  </noscript>
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 00:06, 29 October 2014

This is where you can signup for the keys https://www.google.com/recaptcha/admin#whyrecaptcha

Referrers and Recipients

Make sure the customer has this set up properly as well

#whatever domains they decided to use should go in referrers.
@referers = ('www.domain.com','domain.com');

# @recipients defines the e-mail addresses or domain names that e-mail can   #
# be sent to.  This must be filled in correctly to prevent SPAM and allow    #
# valid addresses to receive e-mail.  Read the documentation to find out how #
# this variable works!!!  It is EXTREMELY IMPORTANT.                         #
# If we are troubleshooting the receiving make sure this has a string of the email and not a variable #
@recipients = '[email protected]';

Use LWP

This will need to be put just before it shows all the &check's down the page

use LWP::UserAgent;

Calling the Check Captcha

You can add this anywhere near &check lines

# Check the captcha challenge and response.
&check_captcha;

Checking the Captcha

This actually checks the captcha that was typed in

##############################################################################
# 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 => 'your_private_key',
          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');
      }
}

Captcha Failure Message

Make sure you put this behind the correct elseif bracket or else this will error

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%gt;
    </td></tr>
   </table>
  </center>
 </body>
</html>
(END ERROR HTML)
    }

The Html Form Page

<script type="text/javascript"
    src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
  </script>
  <noscript>
    <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
        height="300" width="500" frameborder="0"></iframe>

    <textarea name="recaptcha_challenge_field" rows="3" cols="40">
    </textarea><br>
    <input type="hidden" name="recaptcha_response_field"
        value="manual_challenge">
  </noscript>