M
M
Michael2019-12-09 19:30:40
PHP
Michael, 2019-12-09 19:30:40

Can't do a recaptcha on a form?

Hello!
Can't do recaptcha on the form.
I entered the Site Key into the form code.
Recaptcha appeared on the form. But she doesn't work yet.
And here Secret Key I will not understand where to write. We have another site registered in the action, to which I do not have access. Then I won't be able to write the Secret Key ?
Here is the form code

<form id="form-to-join-webinar" class="form-to-join-webinar01" method='POST' action='https://app.syncrm.ru/web_forms/order'>


<input type='text' name='contact[first_name]' value='' placeholder='Имя'/>

<input type='text' name='contact[email]' value='' placeholder='E-mail'/>

<input type='text' name='contact[general_phone]' value='' placeholder='Телефон'/>


  <!-- Тип -->
  <input type='hidden' name='contact[type]' value='3315' />
  <!-- Название -->
  <input type='hidden' name='deal[name]' value='' />
  <!-- Сумма -->
  <input type='hidden' name='deal[amount]' value='' />
  <!-- Воронка -->
  <input type='hidden' name='deal[stage_category]' value='913' />
  <!-- обязательные поля. не удалять! -->
  <input type='hidden' name='redirect_url' value='https://app.syncrm.ru/accounts/sign_up' />
  <input type='hidden' name='token' value='0068b9c09f3a86f243dd8d243120631e' />
  <input type='hidden' name='responsible_id' value='564' />
  <br />

<div class="g-recaptcha" data-sitekey="6LfIFsYUAAAAAP6lIsCImScD0awQP9shuq5-U3Wr" ></div>

  <br />
  <input id="btn-subm" type='submit' value='Отправить заявку' />
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jack Williams, 2019-12-09
@JackWilliams

SecretKey must be stored exclusively on the server. And on the server, the recaptcha is checked using the sitekey and secret key. Here's how it happens:

function v2_captcha_token_checker($v2_captcha_tokens, $secret_key){

    // return false;
    // return true;

    $ch = curl_init();

    $data = array(

      'secret' => $secret_key,
      'response' => $v2_captcha_token

    );

    curl_setopt_array($ch, [

        CURLOPT_HEADER => 0,
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
        CURLOPT_POSTFIELDS => http_build_query($data)

      ]);


  $response = json_decode(curl_exec($ch), true);


  if($response['success']){


    return true;

  }
  else{

    return false;

  }

}
function captcha_response_check()
  {

      include ("captcha_v2_invisible_cnf.php");
      global $answer;

      if (

      (!isset($_POST['captcha_v2_invisible_token'])) ||

      ($_POST['captcha_v2_invisible_token'] == ""))
      {

          $answer["status"] = "ERROR";
          $answer["message"] = 'BAD REQUEST: POST captcha_v2_invisible_token param is required';
          http_response_code(400);

          echo json_encode($answer);
          exit;

      }

      $captcha_v2_invisible_token = $_POST['captcha_v2_invisible_token'];
      $secret_key = $captcha_v2_invisible_cnf['secret_key'];

      $captcha_v2_invisible_token_is_ok = v2_captcha_token_checker($captcha_v2_invisible_token, $secret_key);

      if ($captcha_v2_invisible_token_is_ok)
      {

          $answer["captcha_v2_invisible_token_is_valid"] = true;

      }
      else
      {

          $answer["captcha_v2_invisible_token_is_valid"] = false;
          http_response_code(400);
          $answer["status"] = "ERROR";
          $answer["message"] = 'captcha v2 invisible token is not valid';

          echo json_encode($answer);
          exit;

      }

  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question