My page is registering without google recaptcha .How to validate it can anyone please tell me?

Published 8 months ago by jhansi

Please upgrade to a supported browser to get a reCAPTCHA challenge.

Alternatively if you think you are getting this page in error, please check your internet connection and reload.

Why is this happening to me?

This is appearing on the page.By using this site I used google reCaptcha http://itsolutionstuff.com/post/laravel-5-google-recaptcha-code-and-validation-example-using-anhskohbo-no-captcha-packageexample.html

Best Answer (As Selected By jhansi)
jhansi

register.blade.php


@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Register</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ url('/site-register') }}">
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                            <label for="name" class="col-md-4 control-label">Name</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>

                                @if ($errors->has('name'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('name') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                        <div class="form-group{{ $errors->has('Team') ? ' has-error' : '' }}">
                        
                            <label for="Team" class="col-md-4 control-label">Team</label>
                            
                            
                            <div class="col-md-6">
                            <select name="Team" class="form control">
                  
                  @foreach($teams as $team)
            <option value="{{ $team->Team }}" <?php echo ($team->Team_id==2)? 'selected':'';?>>{{ $team->Team }}</option>  
            
                 @endforeach
                               
                                 


                            </select>
                                @if ($errors->has('Team'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('Team') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                         <div class="form-group{{ $errors->has('Vendor') ? ' has-error' : '' }}">
                        
                            <label for="Vendor" class="col-md-4 control-label">Vendor</label>
                            
                            
                            <div class="col-md-6">
                            <select name="Vendor" class="form control">
                             @foreach($vendors as $vendor)
            <option value="{{ $vendor->Vendor }}" <?php echo ($vendor->Vendor_id==2)? 'selected':'';?> >{{ $vendor->Vendor }}</option>    
@endforeach
                    

                            </select>
                                @if ($errors->has('Vendor'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('Vendor') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>


                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
                            </div>
                        </div>
                        <div class="form-group{{ $errors->has('g-recaptcha-response') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Captcha</label>

                            <div class="col-md-6">
                                                     {!! Form::captcha() !!}


                                @if ($errors->has('g-recaptcha-response'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('g-recaptcha-response') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Register
                                </button>
                            </div>
                        </div>
                    </form>
                   
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

registercontroller.php

<?php

namespace App\Http\Controllers\Auth;
use Illuminate\Support\Facades\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use App\Team;
use App\Vendor;

class RegisterController extends Controller
{
   

    use RegistersUsers;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'Team'=>'max:20',
            'Vendor'=>'max:40',
            'password' => 'required|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
             'Team' => $data['Team'],
              'Vendor' => $data['Vendor'],
            'password' => bcrypt($data['password']),
        ]);
    }
    public function siteRegister()
    {
        return view('siteRegister');
    }

    public function siteRegisterPost(Request $request)
    {
       echo '<pre>################';
        print_r($request->all());
 $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email',
            'password' => 'required|same:password_confirmation',
            'password_confirmation' => 'required',
            'g-recaptcha-response' => 'required|captcha',
        ]);
        print('done');
         $selectData = $request->input('Team');
          $selectData = $request->input('Vendor');


    }
 public function showregistrationform()
{
   
     $teams = Team::all(['Team_id','Team']);
  
     $vendors = Vendor::all(['Vendor_id','Vendor']);
    //echo '<pre>'.print_r($teams,true).'</pre>';

     
    return view('auth.register', [ 'teams' =>$teams,'vendors' => $vendors]);
}

}

web.php

    return view('welcome');
});

Auth::routes();

Route::get('/home', '[email protected]');
Route::get('site-register', 'Auth\[email protected]');
Route::post('site-register', 'Auth\[email protected]');
Route::get('/user','[email protected]');



Route::get('/Team', function () {
    return view('team');
});
Route::get('/teams', '[email protected]');

Route::post('/insert', '[email protected]');

Route::get('/Vendor', function () {
    return view('vendor');
});

Route::get('/vendors', '[email protected]');

Route::post('/increment', '[email protected]');

Step 1: Installation

In first step we will install anhskohbo/no-captcha package for Google reCaptcha code. this package through we can generate generate captcha code for our project. so first fire bellow command in your cmd or terminal:

composer require anhskohbo/no-captcha

Now we need to add provider path and alias path in config/app.php file so open that file and add bellow code.

config/app.php

return [
    ......
    $provides => [
        ......
        ......,
        Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class
    ],
    .....
]
```

I just did the minor changes and it is working well
tisuchi
tisuchi
8 months ago (265,985 XP)

Can you show your code?

jhansi

register.blade.php


@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Register</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ url('/site-register') }}">
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                            <label for="name" class="col-md-4 control-label">Name</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>

                                @if ($errors->has('name'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('name') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                        <div class="form-group{{ $errors->has('Team') ? ' has-error' : '' }}">
                        
                            <label for="Team" class="col-md-4 control-label">Team</label>
                            
                            
                            <div class="col-md-6">
                            <select name="Team" class="form control">
                  
                  @foreach($teams as $team)
            <option value="{{ $team->Team }}" <?php echo ($team->Team_id==2)? 'selected':'';?>>{{ $team->Team }}</option>  
            
                 @endforeach
                               
                                 


                            </select>
                                @if ($errors->has('Team'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('Team') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                         <div class="form-group{{ $errors->has('Vendor') ? ' has-error' : '' }}">
                        
                            <label for="Vendor" class="col-md-4 control-label">Vendor</label>
                            
                            
                            <div class="col-md-6">
                            <select name="Vendor" class="form control">
                             @foreach($vendors as $vendor)
            <option value="{{ $vendor->Vendor }}" <?php echo ($vendor->Vendor_id==2)? 'selected':'';?> >{{ $vendor->Vendor }}</option>    
@endforeach
                    

                            </select>
                                @if ($errors->has('Vendor'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('Vendor') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>


                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
                            </div>
                        </div>
                        <div class="form-group{{ $errors->has('g-recaptcha-response') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Captcha</label>

                            <div class="col-md-6">
                                                     {!! Form::captcha() !!}


                                @if ($errors->has('g-recaptcha-response'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('g-recaptcha-response') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Register
                                </button>
                            </div>
                        </div>
                    </form>
                   
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

registercontroller.php

<?php

namespace App\Http\Controllers\Auth;
use Illuminate\Support\Facades\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use App\Team;
use App\Vendor;

class RegisterController extends Controller
{
   

    use RegistersUsers;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'Team'=>'max:20',
            'Vendor'=>'max:40',
            'password' => 'required|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
             'Team' => $data['Team'],
              'Vendor' => $data['Vendor'],
            'password' => bcrypt($data['password']),
        ]);
    }
    public function siteRegister()
    {
        return view('siteRegister');
    }

    public function siteRegisterPost(Request $request)
    {
       echo '<pre>################';
        print_r($request->all());
 $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email',
            'password' => 'required|same:password_confirmation',
            'password_confirmation' => 'required',
            'g-recaptcha-response' => 'required|captcha',
        ]);
        print('done');
         $selectData = $request->input('Team');
          $selectData = $request->input('Vendor');


    }
 public function showregistrationform()
{
   
     $teams = Team::all(['Team_id','Team']);
  
     $vendors = Vendor::all(['Vendor_id','Vendor']);
    //echo '<pre>'.print_r($teams,true).'</pre>';

     
    return view('auth.register', [ 'teams' =>$teams,'vendors' => $vendors]);
}

}

web.php

    return view('welcome');
});

Auth::routes();

Route::get('/home', '[email protected]');
Route::get('site-register', 'Auth\[email protected]');
Route::post('site-register', 'Auth\[email protected]');
Route::get('/user','[email protected]');



Route::get('/Team', function () {
    return view('team');
});
Route::get('/teams', '[email protected]');

Route::post('/insert', '[email protected]');

Route::get('/Vendor', function () {
    return view('vendor');
});

Route::get('/vendors', '[email protected]');

Route::post('/increment', '[email protected]');

Step 1: Installation

In first step we will install anhskohbo/no-captcha package for Google reCaptcha code. this package through we can generate generate captcha code for our project. so first fire bellow command in your cmd or terminal:

composer require anhskohbo/no-captcha

Now we need to add provider path and alias path in config/app.php file so open that file and add bellow code.

config/app.php

return [
    ......
    $provides => [
        ......
        ......,
        Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class
    ],
    .....
]
```

I just did the minor changes and it is working well
Ishatanjeeb

This is the third-party AIP and it's depend on your browser version.If you have no internet connection then it should be get error because you using API.

tisuchi
tisuchi
8 months ago (265,985 XP)

Did you add environment variables?

NOCAPTCHA_SECRET=[secret-key]
NOCAPTCHA_SITEKEY=[site-key]
jhansi

@tisuchi yes i added in .env file.

tisuchi
tisuchi
8 months ago (265,985 XP)

As @Ishatanjeeb bhai said, Make sure that, you have internet connection...

jhansi

yes,i have internet connection

tisuchi
tisuchi
8 months ago (265,985 XP)

Would you mind to reshape your code a bit?

Here is the code that you can check recaptcha without using any plugin.

In you view-

<div class="g-recaptcha" data-sitekey="your-site-key-will-be-here"></div>
      <input type="hidden" id="terms" name="terms" value="1">
      <input type="hidden" id="referral" name="referral" value="">
</li>

Now, finally in your controller, you need to check it like so-


//recaptcha will generate a textarea name g-recaptcha-response
$captcha = $request->input('g-recaptcha-response');
        

if(empty($captcha)){
   return redirect()
            ->back()
            ->withErrors('Please make sure to select the captcha box before submitting your information')
            ->withInput();
}else{
   $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=Put_your_key_here&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
   if($response['success'] == false)
    {
        return redirect()
                ->back()
                ->withErrors('reCaptcha Error! Please try again.')
                ->withInput();;
    }
    else
    {
        $flag = 0;
    } 
}  

Ref: https://developers.google.com/recaptcha/intro

jhansi

Still it is not working

Ishatanjeeb

can you debug your code?If any error message show then share with us,otherwise we can not solve your problem.

Ishatanjeeb

@jhansi where you check locally or server?

jhansi

By using xampp server in local browser .My problem is without taking any google recaptcha my page is going to login page.can you please help me regarding that?

tisuchi
tisuchi
8 months ago (265,985 XP)

@jhansi...

The code I provide you in above, its working fine for me.

You guy double check that, you wrote everything properly.

Please sign in or create an account to participate in this conversation.