captcha icon indicating copy to clipboard operation
captcha copied to clipboard

Validation failure redirects (302) to /captcha/default?{code}

Open geoff-maddock opened this issue 4 years ago • 4 comments

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 avatar Dec 11 '21 22:12 geoff-maddock

@geoff-maddock did you find any solution to this?

vishu1034 avatar Feb 21 '22 15:02 vishu1034

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}

wakibul avatar Apr 13 '22 06:04 wakibul

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');
        }

moosti avatar Sep 27 '22 01:09 moosti

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

Reymoh75 avatar Jan 18 '23 06:01 Reymoh75