bodeezy / recaptcha
适用于Laravel 4的reCAPTCHA验证器
1.1.0
2014-12-05 13:02 UTC
Requires
- php: >=5.3.0
- illuminate/support: *
This package is not auto-updated.
Last update: 2024-09-24 15:15:18 UTC
README
一个适用于Laravel 4的reCAPTCHA验证器。
安装
将以下行添加到composer.json文件中的require部分
{
"require": {
"bodeezy/recaptcha": "dev-master"
}
}
Laravel 4配置
- 将
Greggilbert\Recaptcha\RecaptchaServiceProvider添加到app/config/app.php中的服务提供者列表。 - 运行
php artisan config:publish greggilbert/recaptcha。 - 在
app/config/packages/greggilbert/recaptcha/config.php中,输入您的reCAPTCHA公钥和私钥。 - 将以下行添加到
app/lang/[lang]/validation.php
"recaptcha" => 'The :attribute field is not correct.',
使用方法
- 在您的表单中,使用
Form::captcha()输出标记。 - 在验证规则中添加以下内容
$rules = array( // ... 'recaptcha_response_field' => 'required|recaptcha', };
还建议在验证时添加required。
自定义
reCAPTCHA允许通过多种选项自定义小部件,这些选项在官方文档中列出。您可以通过多种方式配置验证码的输出。
在config.php中,您可以创建一个options数组来设置默认行为。例如
// ... 'options' => array( 'theme' => 'white', ),
将默认所有reCAPTCHA为白色主题。如果您想进一步自定义,可以通过表单选项传递选项
echo Form::captcha(array('theme' => 'blackglass'));
或者,如果您想设置默认模板而不是标准模板,可以使用配置
// ... 'template' => 'customCaptcha',
或者您可以通过表单选项传递它
echo Form::captcha(array('template' => 'customCaptcha'));
传递给Form::captcha的选项将始终覆盖配置。
要更改验证码的语言,只需将语言作为选项的一部分传递即可
'options' => array( 'lang' => 'fr', ),
您可以在配置和通过Form::captcha()调用中这样做。
V2 (无CAPTCHA reCAPTCHA) 支持
要使用新的reCAPTCHA(见https://developers.google.com/recaptcha/docs/display),您需要在配置中启用v2设置
// ... 'v2' => true,
注意,如果您以前使用过reCAPTCHA v1,您还需要生成一组新的密钥。您可以在https://www.google.com/recaptcha/admin#list请求密钥
验证规则也需要修改为以下内容
$rules = array( // ... 'g-recaptcha-response' => 'required|recaptcha', };
限制
由于Google显示recaptcha的方式,如果从ajax调用加载表单,此包将无法工作。如果需要这样做,应使用Google提供的方法