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
- Host: GitHub
- URL: https://github.com/rareloop/lumberjack-recaptcha
- Owner: Rareloop
- License: mit
- Created: 2020-04-03T12:35:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-05T14:13:12.000Z (almost 3 years ago)
- Last Synced: 2025-01-30T12:41:15.575Z (about 1 year ago)
- Language: PHP
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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
```