Validation failure redirects (302) to /captcha/default?{code}
Setting this up for the first time on a Laravel 8 app in order to protect my site from having a bunch of random bot registrations.
I followed some examples on this page, although I applied them to my RegisterController and register blade template. https://www.positronx.io/laravel-captcha-tutorial-example/
When I submit the form and the validation passes - ie. the captcha is correct - then the form submits normally.
But when the captcha fails, it does a 302 redirect to /captcha/default?{code}
I'm looking at the README docs but I don't see where this would be specified or even why it would redirect.
Anyone have tips here?
@geoff-maddock did you find any solution to this?
same issue .. When I submit the form and the validation passes - ie. the captcha is correct - then the form submits normally.
But when the captcha fails, it does a 302 redirect to /captcha/default?{code}
Its because laravel send validation fail result to previous url (save in _previous session key) by default, and when use captcha latest url will be captcha image source.
You can handle redirect manually :
1 - In FormRequest class
class SomeRequest extends FormRequest
{
.
.
.
public function rules()
{
$this->redirect = route('custom');
return [
'somerule',
'captcha' => 'required|captcha',
]
}
2- In controller
$validator = Validator::make($request->all(), [
'somerule',
'captcha' => 'required|captcha',
]);
if ($validator->fails()) {
throw ValidationException::withMessages($validator->errors()->toArray())
->redirectTo('/customroute');
}
Setting this up for the first time on a Laravel 8 app in order to protect my site from having a bunch of random bot registrations.
I followed some examples on this page, although I applied them to my RegisterController and register blade template. https://www.positronx.io/laravel-captcha-tutorial-example/
When I submit the form and the validation passes - ie. the captcha is correct - then the form submits normally.
But when the captcha fails, it does a 302 redirect to /captcha/default?{code}
I'm looking at the README docs but I don't see where this would be specified or even why it would redirect. Anyone have tips here?
you should use captcha_check() method. see this : https://github.com/mewebstudio/captcha/issues/250#issuecomment-1383939350