ARCANEDEV/noCAPTCHA

Laravel invisible ex

zKoz210 opened this issue · 15 comments

  • noCaptcha Version: latest
  • Laravel Version: 5.4.21
  • PHP Version: 7.1.0

Description:

Please add example invisible re-captcha for Laravel, thanks!

I really don't know how to do it in Laravel...

Example form

<form id="loginForm" action="{{ route('auth.login') }}" method="POST">
    {!! csrf_field() !!}

    <div class="form-group has-feedback">
        <input name="user" class="form-control" value="{{ old('user') }}" placeholder="@lang('strings.user_identifier')">
        <span class="fa fa-envelope form-control-feedback"></span>
    </div>
    <div class="form-group has-feedback">
        <input type="password" name="password" class="form-control" placeholder="@lang('strings.password')">
        <span class="fa fa-lock form-control-feedback"></span>
    </div>
    {!! Captcha::display() !!}
    <div class="row">
        <div class="col-xs-4">
            <button type="submit" class="btn btn-primary btn-block btn-flat">@lang('auth.sign_in')</button>
        </div>
    </div>
</form>

Use Captcha::button('Send', ['data-badge' => 'inline']) instead of Captcha::display().

And the bottom :

{!! $captcha->script() !!}
<script>
    function onSubmit(token) {
        document.getElementById("loginForm").submit();
    }
</script>

Thank you very much!

image

Hmm..

    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->username() => 'required|string',
            'password' => 'required|string',
            'g-recaptcha-response' => ['required', 'captcha'],
        ]);
    }

image
image

How can I fill the invisible captcha?

Can you try to set the captcha name ?

{!! Captcha::button(trans('auth.sign_in'), ['name' => 'g-recaptcha-response', 'class' => '...']) !!}

And to check your inputs:

protected function validateLogin(Request $request)
{
    dd($request->all());  // Check that you get all the inputs including the 'g-recaptcha-response'

    $this->validate($request, [
        $this->username() => 'required|string',
        'password' => 'required|string',
        'g-recaptcha-response' => ['required', 'captcha'],
    ]);
}
array:4 [▼
  "_token" => "naL27bhOuk9HH8dbzg8UWV3pXWVG4DGyatKSWcoZ"
  "user" => "zKoz210"
  "password" => "MyPassword"
  "g-recaptcha-response" => ""
]

image

Are you sending the form with ajax ?

No, default auth from Laravel

Ok, i'm going to check this and see if i can reproduce your issue.

Okay, thanks!

OK, i see the issue, if you want to apply custom css class, you can do it but you need to keep the default recaptcha class, try something like this:

{!! Captcha::button(trans('auth.sign_in'), ['class' => 'g-recaptcha btn btn-primary btn-block btn-flat']) !!}

You can check the official documentation for more details: https://developers.google.com/recaptcha/docs/invisible

@arcanedev-maroc You are great! Thank you very much for this packet. It helped me too!

You're welcome @Pub4Game 👍