gonzakpo / recaptcha-bundle
Recaptcha Bundle 用于创建 Google NoCaptcha Recaptcha v2 的表单元素
1.0.1
2020-07-13 12:59 UTC
Requires
- php: >=5.3.8
- doctrine/doctrine-bundle: *
- symfony/framework-bundle: ~2.3
- twig/twig: *
This package is auto-updated.
Last update: 2024-09-13 22:37:25 UTC
README
Symfony2 Bundle for Google reCaptcha v2。它提供了一个表单类型,可以包含在您的表单中,并具有特定的验证器。
安装
使用 composer 安装
composer require gonzakpo/recaptcha-bundle
在项目中启用该组件
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Pv\RecaptchaBundle\PvRecaptchaBundle(), // ... ); }
配置
将以下行添加到您的 config.yml
# app/config/config.yml # Include the recaptcha widget twig: form: resources: # ... - 'PvRecaptchaBundle:Form:recaptcha_widget.html.twig' # ... # Recaptcha Configuration pv_recaptcha: recaptcha_public_key: 'your-public-key' recaptcha_private_key: 'your-private-key'
使用方法
Recaptcha V2
将以下代码添加到您的表单类中
public function buildForm(FormBuilderInterface $builder, array $options) { $builder // ... ->add('recaptcha', 'pv_recaptcha', array( 'label' => 'Your label', 'mapped' => false, )) // ... ; }
然后,在您的twig视图中显示小部件,如下所示
{{ form_label(form.recaptcha) }} {{ form_widget(form.recaptcha) }} {{ form_errors(form.recaptcha) }}
不可见 Recaptcha
将以下代码添加到您的表单类中
public function buildForm(FormBuilderInterface $builder, array $options) { $builder // ... ->add('recaptcha', 'pv_recaptcha', array( 'label' => false, 'mapped' => false, 'invisible' => true, 'form_id' => 'your-form-element-id' )) // ... ; }
待办事项
- 创建一个标签