acrobat / recaptcha-bundle
此包已被弃用且不再维护。未建议替代包。
此包提供将 reCAPTCHA 集成到 symfony2 的简便方法
v2.0.0
2014-10-19 09:24 UTC
Requires
- php: >=5.3.3
- symfony/config: ~2.3
- symfony/dependency-injection: ~2.3
- symfony/form: ~2.3
- symfony/http-kernel: ~2.3
- symfony/validator: ~2.3
Requires (Dev)
- liip/rmt: ~1.0
- phpunit/phpunit: 4.3.*
This package is auto-updated.
Last update: 2023-12-17 08:10:54 UTC
README
此包提供 reCAPTCHA 与 symfony2 表单的集成。
安装
步骤 1: 使用 Composer 启用 Bundle
使用 Composer 安装 AcrobatRecaptchaBundle,只需运行以下命令:
Symfony 2.3 安装
$ php composer.phar require acrobat/recaptcha-bundle:~1.0
Symfony >= 2.4 安装
$ php composer.phar require acrobat/recaptcha-bundle:~2.0
注意:在 RecaptchaBundle 2.0 中,我们放弃了 symfony 2.3 的支持,请参阅问题 #4。1.0 和 2.0 两个版本都将得到维护。
这将向 composer.json
文件中添加配置行,并安装此包的最新稳定版本。
剩下的工作是将你的 AppKernel.php
文件更新,并注册新包。
<?php // in AppKernel::registerBundles() $bundles = array( // ... new Acrobat\Bundle\RecaptchaBundle\AcrobatRecaptchaBundle(), // ... );
步骤 2: 配置包
你的 reCAPTCHA 的公钥和私钥可以在你的 recaptcha 管理页面 找到。将以下内容添加到你的 config.yml
文件中:
# app/config/config.yml acrobat_recaptcha: public_key: here_is_your_public_key private_key: here_is_your_private_key locale: %kernel.default_locale%
注意:只需 public_key 和 private_key 是必需的,其他设置将在未定义时使用默认值。
你可以禁用 reCAPTCHA(例如在本地或测试环境中)
# app/config/config.yml acrobat_recaptcha: // ... enabled: false
使用 Ajax 加载 reCAPTCHA
# app/config/config.yml acrobat_recaptcha: // ... ajax: true
使用 https 进行 reCAPTCHA 连接
# app/config/config.yml acrobat_recaptcha: // ... https: auto
可能的值
- on : 总是使用 https
- off : 总是使用 http
- auto : 让浏览器根据原始请求协议(默认)决定使用哪个协议
基本用法
在表单中使用
添加以下行以创建 reCAPTCHA 字段
<?php public function buildForm(FormBuilder $builder, array $options) { // ... $builder->add('recaptcha', 'recaptcha'); }
你可以通过 options 属性传递额外的选项给 reCAPTCHA
<?php public function buildForm(FormBuilder $builder, array $options) { // ... $builder->add('recaptcha', 'recaptcha', array( 'attr' => array( 'options' => array( 'theme' => 'clean' ) ) )); // ... }
有效选项列表
- theme
- lang
- custom_translations
- custom_theme_widget
- tabindex
访问 Customizing the Look and Feel of reCAPTCHA 了解自定义细节。
验证
RecaptchaType
有内置的验证器,你无需设置任何东西!
你可以通过从表单配置中移除现有的验证器来 禁用 默认验证。
<?php public function buildForm(FormBuilder $builder, array $options) { // ... $builder->add('recaptcha', 'recaptcha', array( // only for disabling validation 'constraints' => array() )); }