input.ucaptcha.php
Поле «Проверка на человека (uCAPTCHA)»
Вызывается из:
Смотрите описание Cms\Root\Form\Field\Ucaptcha
Исходный код
<?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('ucaptcha_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, '_'), ucaptcha = document.getElementById(id), rendered = false;
window[callbackName] = () => {
if (window.urecaptcha && window.urecaptcha.render) {
if (!rendered) {
urecaptcha.render(ucaptcha, { sitekey: ucaptcha.getAttribute('data-sitekey') });
rendered = true;
}
}
};
cmsRequire(['https://captcha.uslugi.site/recaptcha/api.js?render=explicit&onload=' + callbackName], () => (window[callbackName])());
})();
</script>