milanpol/recaptcha-bundle

Symfony的Recaptcha包装器

安装: 906

依赖: 0

建议者: 0

安全: 0

星级: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

V1.3 2021-06-30 08:04 UTC

This package is auto-updated.

Last update: 2023-08-29 02:51:28 UTC


README

使用方法

将任何表单扩展到AbstractRecaptchaType。这需要您定义getExpectedAction()。返回预期操作(例如,对于联系表单返回contact)。

接下来,在包含表单的twig模板中,包括以下内容

{% include '@EsitesRecaptcha/recaptcha/recaptcha.html.twig' %}

最后,使用php bin/console assets:install安装资源

错误

当recaptcha检查失败时,将向表单添加错误。要显示它,使用

{{ form_errors(form) }}

消息可以通过在validators.nl.yml中定义以下内容进行翻译

error:
    recaptcha_failed_to_validate: 'Recaptcha failed!'

完整配置

esites_recaptcha:
    enable_recaptcha: true   # default value
    recaptcha_key: google_recaptcha_key   # required, the key from the google recaptcha admin dashboard
    recaptcha_secret: google_recaptcha_secret   # required, the secret key from the google recaptcha admin dashboard
    recaptcha_score: 0.5   # default value, the minimum score a visitor has to score to not be flagged as a bot
    expected_hostname: e-sites.nl   # not required, the expected hostname in the google recaptcha response
    use_client_ip: true   # default value, also sends the clients ip to verify the recaptcha request

手动更新Recaptcha

选择要更新的recaptcha元素(隐藏的输入),然后调用setRecaptcha();

setRecaptcha(document.querySelector('#recaptchaObject'));