0

I have simple code in PHP and trying to check my form with reCaptcha.

I already tried v3 or v2 and the problem is the same.

All links are correct, I have no table in form, and keys from console admin are right.

Is there any solution to how I can fix it and have reCaptcha n my form?

MY CODE:

<form method="POST" action="_inc/calc.php">
     <div class="form-field">
          <textarea name="FormMessage" id="message" rows="5"></textarea>
          <label for="message">Správa</label>
     </div>

     <?php
          require_once('_inc/recaptchalib.php');
          $publickey = "xxx"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
     ?>

     <button type="submit" class="btn btn__main">
          Odoslať
     </button>
</form>

calc.php

<?php

$privatekey = "xxx";
require_once('recaptchalib.php');
$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 ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
} else {
  

    require 'mail-sender.php';
    require 'adminmail-sender.php';

    header("Location: https://aptcare.sk/dakujeme");


}

ERROR: enter image description here

How can I

Matúš Rebroš
  • 115
  • 1
  • 9
  • Your question is similar to this https://stackoverflow.com/questions/1264703/google-recaptcha-keep-getting-incorrect-captcha-sol – Sachin Jul 25 '22 at 11:06
  • What is in recaptchalib? – geertjanknapen Jul 25 '22 at 11:38
  • 1
    So `$_POST["recaptcha_challenge_field"]` and `$_POST["recaptcha_response_field"]` apparently are not set. Have you checked what your _rendered_ form looks like, did `echo recaptcha_get_html($publickey);` create the correct form fields as expected? – CBroe Jul 25 '22 at 11:55
  • Figure out why the recaptcha fields are not being passed into the form (are the keys incorrect) and you should be able to fix the sol error – aynber Jul 25 '22 at 11:57

0 Answers0