2017 © Pedro Peláez
 

library invisible-recaptcha

Invisible reCAPTCHA For Laravel.

image

albertcht/invisible-recaptcha

Invisible reCAPTCHA For Laravel.

  • Wednesday, June 20, 2018
  • by albertcht
  • Repository
  • 18 Watchers
  • 382 Stars
  • 68,814 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 42 Forks
  • 5 Open issues
  • 16 Versions
  • 28 % Grown

The README.md

Invisible reCAPTCHA

php-badge packagist-badge Total Downloads travis-badge, (*1)

invisible_recaptcha_demo, (*2)

Why Invisible reCAPTCHA?

Invisible reCAPTCHA is an improved version of reCAPTCHA v2(no captcha). In reCAPTCHA v2, users need to click the button: "I'm not a robot" to prove they are human. In invisible reCAPTCHA, there will be not embed a captcha box for users to click. It's totally invisible! Only the badge will show on the buttom of the page to hint users that your website is using this technology. (The badge could be hidden, but not suggested.), (*3)

Notice

  • The master branch doesn't support multi captchas feature, please use multi-forms branch if you need it. (Most of the time you are misusing recaptcha when you try to put multiple captchas in one page.)

Installation

composer require albertcht/invisible-recaptcha

Laravel 5

Setup

Add ServiceProvider to the providers array in app/config/app.php., (*4)

AlbertCht\InvisibleReCaptcha\InvisibleReCaptchaServiceProvider::class,

It also supports package discovery for Laravel 5.5., (*5)

Configuration

Before you set your config, remember to choose invisible reCAPTCHA while applying for keys. invisible_recaptcha_setting, (*6)

Add INVISIBLE_RECAPTCHA_SITEKEY, INVISIBLE_RECAPTCHA_SECRETKEY to .env file., (*7)

// required
INVISIBLE_RECAPTCHA_SITEKEY={siteKey}
INVISIBLE_RECAPTCHA_SECRETKEY={secretKey}

// optional
INVISIBLE_RECAPTCHA_BADGEHIDE=false
INVISIBLE_RECAPTCHA_DATABADGE='bottomright'
INVISIBLE_RECAPTCHA_TIMEOUT=5
INVISIBLE_RECAPTCHA_DEBUG=false

There are three different captcha styles you can set: bottomright, bottomleft, inline, (*8)

If you set INVISIBLE_RECAPTCHA_BADGEHIDE to true, you can hide the badge logo., (*9)

You can see the binding status of those catcha elements on browser console by setting INVISIBLE_RECAPTCHA_DEBUG as true., (*10)

Usage

Before you render the captcha, please keep those notices in mind:, (*11)

  • render() or renderHTML() function needs to be called within a form element.
  • You have to ensure the type attribute of your submit button has to be submit.
  • There can only be one submit button in your form.
Display reCAPTCHA in Your View
{!! app('captcha')->render() !!}

// or you can use this in blade
@captcha

With custom language support:, (*12)

{!! app('captcha')->render('en') !!}

// or you can use this in blade
@captcha('en')
Usage with Javascript frameworks like VueJS:

The render() process includes three distinct sections that can be rendered separately incase you're using the package with a framework like VueJS which throws console errors when <script> tags are included in templates., (*13)

You can render the polyfill (do this somewhere like the head of your HTML:), (*14)

{!! app('captcha')->renderPolyfill() !!}
// Or with blade directive:
@captchaPolyfill

You can render the HTML using this following, this needs to be INSIDE your <form> tag:, (*15)

{!! app('captcha')->renderCaptchaHTML() !!}
// Or with blade directive:
@captchaHTML

And you can render the neccessary <script> tags including the optional language support by using:, (*16)

// The argument is optional.
{!! app('captcha')->renderFooterJS('en') !!}

// Or with blade directive:
@captchaScripts
// blade directive, with language support:
@captchaScripts('en')

Validation

Add 'g-recaptcha-response' => 'required|captcha' to rules array., (*17)

$validate = Validator::make(Input::all(), [
    'g-recaptcha-response' => 'required|captcha'
]);

CodeIgniter 3.x

set in application/config/config.php :, (*18)

$config['composer_autoload'] = TRUE;

add lines in application/config/config.php :, (*19)

$config['recaptcha.sitekey'] = 'sitekey'; 
$config['recaptcha.secret'] = 'secretkey';
// optional
$config['recaptcha.options'] = [
    'hideBadge' => false,
    'dataBadge' => 'bottomright',
    'timeout' => 5,
    'debug' => false
];

In controller, use:, (*20)

$data['captcha'] = new \AlbertCht\InvisibleReCaptcha\InvisibleReCaptcha(
    $this->config->item('recaptcha.sitekey'),
    $this->config->item('recaptcha.secret'),
    $this->config->item('recaptcha.options'),
);

In view, in your form:, (*21)

<?php echo $captcha->render(); ?>

Then back in your controller you can verify it:, (*22)

$captcha->verifyResponse($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);

Without Laravel or CodeIgniter

Checkout example below:, (*23)

 false,
    'dataBadge' => 'bottomright',
    'timeout' => 5,
    'debug' => false
];
$captcha = new \AlbertCht\InvisibleReCaptcha\InvisibleReCaptcha($siteKey, $secretKey, $options);

// you can override single option config like this
$captcha->setOption('debug', true);

if (!empty($_POST)) {
    var_dump($captcha->verifyResponse($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']));
    exit();
}

?>



render(); ?>

Take Control of Submit Function

Use this function only when you need to take all control after clicking submit button. Recaptcha validation will not be triggered if you return false in this function., (*24)

_beforeSubmit = function(e) {
    console.log('submit button clicked.');
    // do other things before captcha validation
    // e represents reference to original form submit event
    // return true if you want to continue triggering captcha validation, otherwise return false
    return false;
}

Customize Submit Function

If you want to customize your submit function, for example: doing something after click the submit button or changing your submit to ajax call, etc., (*25)

The only thing you need to do is to implement _submitEvent in javascript, (*26)

_submitEvent = function() {
    console.log('submit button clicked.');
    // write your logic here
    // submit your form
    _submitForm();
}

Here's an example to use an ajax submit (using jquery selector), (*27)

_submitEvent = function() {
    $.ajax({
        type: "POST",
        url: "{{route('message.send')}}",
         data: {
            "name": $("#name").val(),
            "email": $("#email").val(),
            "content": $("#content").val(),
            // important! don't forget to send `g-recaptcha-response`
            "g-recaptcha-response": $("#g-recaptcha-response").val()
        },
        dataType: "json",
        success: function(data) {
            // success logic
        },
        error: function(data) {
            // error logic
        }
    });
};

Example Repository

Repo: https://github.com/albertcht/invisible-recaptcha-example, (*28)

This repo demonstrates how to use this package with ajax way., (*29)

Showcases

Credits

Support on Beerpay

Hey dude! Help me out for a couple of :beers:!, (*30)

Beerpay Beerpay, (*31)

The Versions

20/06 2018

dev-master

9999999-dev

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

15/05 2018

v1.8.3

1.8.3.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

04/05 2018

dev-multi-forms

dev-multi-forms

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

29/04 2018

dev-develop

dev-develop

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

12/02 2018

v1.8.2

1.8.2.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

24/12 2017

v1.8.1

1.8.1.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

30/09 2017

v1.8

1.8.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

24/09 2017

v1.7.1

1.7.1.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

03/09 2017

1.7

1.7.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

03/07 2017

v1.6

1.6.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

02/07 2017

v1.5

1.5.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

08/06 2017

v1.4

1.4.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

28/05 2017

v1.3

1.3.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

17/05 2017

v1.2

1.2.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

06/05 2017

v1.1

1.1.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel php captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha

04/05 2017

v1.0

1.0.0.0

Invisible reCAPTCHA For Laravel.

  Sources   Download

MIT

The Requires

 

laravel captcha laravel5 recaptcha no-captcha invisible invisible-recaptcha