input.recaptcha.php
Поле «Проверка на человека (reCAPTCHA)»
Вызывается из:
Смотрите описание Cms\Root\Form\Field\Recaptcha
Исходный код
<?php
$attributes = $Field->getFieldInputAttributes(array(
'grid-margin' => $Field->getInputMargin(),
'grid-width' => $Field->getInputWidth(),
'class' => 'field-input field-input--' . $Field->type,
));
print '<span';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '>';
$attributes = $Field->getInputAttributes(array(
'class' => 'g-recaptcha',
'id' => $Field->id('-input'),
'data-placeholder' => strval($Field->placeholder) !== '' ? htmlspecialchars($Field->placeholder) : null,
'data-required' => $Field->required ? 'Y' : null,
'data-readonly' => $Field->readonly ? 'Y' : null,
'data-disabled' => $Field->disabled ? 'Y' : null,
'data-sitekey' => $Conf->get('recaptcha_sitekey'),
));
print '<div';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '></div>';
print '</span>';
?>
<script>
(() => {
let id = <?=$Field->jId('-input')?>, callbackName = id.replace(/\W/g, '_'), recaptcha = document.getElementById(id), rendered = false;
window[callbackName] = () => {
if (window.grecaptcha && window.grecaptcha.render) {
if (!rendered) {
grecaptcha.render(recaptcha, { sitekey: recaptcha.getAttribute('data-sitekey') });
rendered = true;
}
}
};
cmsRequire(['https://www.google.com/recaptcha/api.js?render=explicit&onload=' + callbackName], () => (window[callbackName])());
})();
</script>