An open API service indexing awesome lists of open source software.

https://github.com/rareloop/lumberjack-recaptcha

Simple ReCAPTCHA integration with Lumberjack
https://github.com/rareloop/lumberjack-recaptcha

Last synced: 3 months ago
JSON representation

Simple ReCAPTCHA integration with Lumberjack

Awesome Lists containing this project

README

          

# Lumberjack ReCAPTCHA

This package provides a simple integration for ReCAPTCHA v2 with Lumberjack and the [`lumberjack-validation`](https://github.com/rareloop/lumberjack-validation) package.

## Installation

`composer require rareloop/lumberjack-recaptcha`

Once installed, register the Service Provider in config/app.php:

```php
'providers' => [
...

Rareloop\Lumberjack\Recaptcha\RecaptchaServiceProvider::class,

...
],
```

Copy the example `config/recaptcha.php` file to you theme directory.

Add your ReCAPTCHA credentials to your `.env` file:

```
GOOGLE_RECAPTCHA_KEY="ABC123"
GOOGLE_RECAPTCHA_SECRET="ABC123"

# Optional, if you need to specify the hostname directly
GOOGLE_RECAPTCHA_HOSTNAME="my-hostname.com"
```

## Usage

Make sure you call the `recaptcha()` Twig function in the form that you wish to add support to:

```html


{{ recaptcha() }}
Submit

```

And then add the validation to your Form class to ensure that it is checked:

```php
'required',
'g-recaptcha-response' => ['required', 'recaptcha'],
];
}

```

## Showing an error

You may also want to show an error if the ReCAPTCHA fails for some reason. Assuming you're passing the standard `errors` array into your view you can simply check for the presence of the `g-recaptcha-response` key:

```html


{{ recaptcha() }}
{% if errors['g-recaptcha-response'] %}
{% for error in errors['g-recaptcha-response'] %}

{{ error }}


{% endfor %}
{% endif %}
Submit

```