Package Data | |
---|---|
Maintainer Username: | bodeezy |
Maintainer Contact: | greg@greg-gilbert.com (Greg Gilbert) |
Package Create Date: | 2014-12-05 |
Package Last Update: | 2014-12-05 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-17 03:02:00 |
Package Statistics | |
---|---|
Total Downloads: | 188 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A reCAPTCHA Validator for Laravel 4.
Add the following line to the require
section of composer.json
:
{
"require": {
"bodeezy/recaptcha": "dev-master"
}
}
Greggilbert\Recaptcha\RecaptchaServiceProvider
to the service provider list in app/config/app.php
.php artisan config:publish greggilbert/recaptcha
.app/config/packages/greggilbert/recaptcha/config.php
, enter your reCAPTCHA public and private keys.app/lang/[lang]/validation.php
: "recaptcha" => 'The :attribute field is not correct.',
Form::captcha()
to echo out the markup. $rules = array(
// ...
'recaptcha_response_field' => 'required|recaptcha',
};
It's also recommended to add required
when validating.
reCAPTCHA allows for customization of the widget through a number of options, listed at the official documentation. You can configure the output of the captcha in several ways.
In the config.php
, you can create an options
array to set the default behavior. For example:
// ...
'options' => array(
'theme' => 'white',
),
would default all the reCAPTCHAs to the white theme. If you want to further customize, you can pass options through the Form option:
echo Form::captcha(array('theme' => 'blackglass'));
Alternatively, if you want to set a default template instead of the standard one, you can use the config:
// ...
'template' => 'customCaptcha',
or you can pass it in through the Form option:
echo Form::captcha(array('template' => 'customCaptcha'));
Options passed into Form::captcha
will always supercede the configuration.
To change the language of the captcha, simply pass in a language as part of the options:
'options' => array(
'lang' => 'fr',
),
You can do this both in the config and through the Form::captcha()
call.
To make use of the new reCAPTCHA (see https://developers.google.com/recaptcha/docs/display), you will need to enable the v2 setting in the config:
// ...
'v2' => true,
Note that you will also have to generate a new set of keys if you have previously used reCAPTCHA v1. You can request keys at: https://www.google.com/recaptcha/admin#list
The validation rules will also need to be modified to the below:
$rules = array(
// ...
'g-recaptcha-response' => 'required|recaptcha',
};
Because of Google's way of displaying the recaptcha, this package won't work if you load your form from an ajax call. If you need to do it you should use that method provided by Google :