Reputation: 385
I am newbie in Laravel. I've used this recaptcha package: https://github.com/greggilbert/recaptcha And the documentation saids that: In your validation rules, add the following:
$rules = array(
// ...
'g-recaptcha-response' => 'required|recaptcha',
};
By the way I use the laravel 5's Registrar:
<?php namespace taxman\Services;
use taxman\User;
use Validator;
use Illuminate\Contracts\Auth\Registrar as RegistrarContract;
class Registrar implements RegistrarContract {
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
public function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:4',
'telephone' => 'required',
'g-recaptcha-response' => 'required|recaptcha',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
public function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
But in this case the laravel return with a error message: "The g-recaptcha-response is required", however in the view I used this command:
<div class="form-group">
{!! Recaptcha::render() !!}
</div>
And yes, the field is not empty!
So, I think, I should put the 'g-recaptcha-response' => 'required|recaptcha'
somewhere else?
Because it seems, in the Registrar's validator does not work.
Upvotes: 5
Views: 7239
Reputation: 111
if someone is still pulling their hair because of this issue just remove the 'recaptcha'
in validation rule.
use
'g-recaptcha-response' => 'required'
instead of
'g-recaptcha-response' => 'required|recaptcha'
see http://tuts.codingo.me/google-recaptcha-in-laravel-application/
Upvotes: 11
Reputation: 2339
According to the documentation https://developers.google.com/recaptcha/docs/verify, you need to check g-recaptcha-response POST parameter. So pass it to the validator() function.
Upvotes: 0
Reputation: 1
if you paste the following in the controller where this action happends it should work.
$this->validate($request,['g-recaptcha-response' => 'required|recaptcha']);
Upvotes: 0