V
V
Vadim Timoshenko2020-01-27 17:39:41
1C-Bitrix
Vadim Timoshenko, 2020-01-27 17:39:41

How to install recapcha v3 on 1C-Bitrix?

In general, I set myself the task of independently connecting captcha to the feedback form. And not a simple "I'm not a robot", but version #3.

I found a guide: https://fstrange.ru/coder/php/bitrix-recaptcha-v3.html
And started to perform the task using it.

The first thing I did was to find the template file that displays my form:
/local/templates/site_name/components/bitrix/form.result.new/.default/template.php I

added a hidden field to it:

<input type="hidden" name="recaptcha_response" id="recaptchaResponse">


Next, in the /local/templates/site_name/components/bitrix/form.result.new/.default/ folder, I created the component_epilog.php file and filled it with this code:

<?php
  $APPLICATION->AddHeadScript("/www.google.com/recaptcha/api.js?render=6Ld4DtEUAAAAAGWUfXOC07l8ca0NKwkeYaEbYciS");
  $APPLICATION->AddHeadScript("
  <script>
  var onloadCallbackRecap = function() {
  grecaptcha.ready(function () {
  grecaptcha.execute('6Ld4DtEUAAAAAGWUfXOC07l8ca0NKwkeYaEbYciS', { action: 'contact_callback' }).then(function (token) {
  var recaptchaResponse = document.getElementById('recaptchaResponse');
  recaptchaResponse.value = token;
  });
  });
  };
  </script>
  ");
?>


Where - 6Ld4DtEUAAAAAGWUfXOC07l8ca0NKwkeYaEbYciS site key.

If I understand correctly, the script code that I inserted above should appear in the site code. But he is not. Cleaned cache. What did I do wrong at this stage?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Prokhorov, 2020-01-29
@PbI6A_KuT

$APPLICATION->AddHeadScript("
  <script>
  var onloadCallbackRecap
// ..e

Replace AddHeadScript with AddHeadString. In general, what prevents you from using the script.js of the component, it is intended for this. The result will be the same, but it will be much more convenient to work. Or just write in the script tag.
And the methods you described have long been depricated, instead of them there is Bitrix\Main\Page\Asset

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question