implementing recaptcha V2 into Form2Mail.php

123 views
Skip to first unread message

Dalton

unread,
Sep 1, 2016, 10:11:42 AM9/1/16
to reCAPTCHA
Hi all,
I was using recaptcha v1 perfectly well but am having issues getting V 2 working. My form submissions are handled by Form2Mail and previously I simply added the following php at the beginning of the Form2mail.php file and all worked.

 <?php
  require_once('recaptchalib.php');
  $privatekey = "####################";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("Sorry the reCAPTCHA verification wasn't entered correctly. Please go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }
  ?>

Now using V2 the above code no longer works, if I add the following code to the head of my html page containing the form it all works but I dont want to have the code at the top of my html page as it becomes visible to anyone who does a simple view source.

<?php
    if(isset($_POST['submit'])){
    $privatekey = "################";
    
    $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);


?>

I am not a php programmer so would appreciate any help anyone can give to advise what I need to do to have the verification and private key back in the form2mail.php file again.

Thanks in advance for any help provided.

Jeff Smith

unread,
Dec 7, 2016, 11:51:04 AM12/7/16
to reCAPTCHA
Hi. 

Was a solution to this ever provided? I am using HDWForm2 Mail, Form2Mail.php.

Recaptcha verifies correctly on its own. However, my form still processes without requiring the reCaptcha.  

How can I get these two to work together?
Message has been deleted

Benjamin

unread,
Dec 13, 2016, 6:53:16 PM12/13/16
to reCAPTCHA
PHP code is actually hidden when you view the page source, so you shouldn't have to worry about that.


On Thursday, September 1, 2016 at 9:11:42 AM UTC-5, Dalton wrote:
Reply all
Reply to author
Forward
0 new messages