rareloop / lumberjack-recaptcha
Installs: 8 194
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- google/recaptcha: ^1.2
- rareloop/lumberjack-core: ^5.0.0||^6.0.0
- rareloop/lumberjack-validation: ^1.0.0
Requires (Dev)
- brain/monkey: ^2.0.2
- codedungeon/phpunit-result-printer: ^0.4.4
- mockery/mockery: ^1.0.0
- phpunit/phpunit: ^6.0
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-12-05 17:37:06 UTC
README
This package provides a simple integration for ReCAPTCHA v2 with Lumberjack and the lumberjack-validation
package.
Installation
composer require rareloop/lumberjack-recaptcha
Once installed, register the Service Provider in config/app.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:
<form method="" action=""> <input name="my-input-name" type="text"> {{ recaptcha() }} <button type-"submit">Submit</button> </form>
And then add the validation to your Form class to ensure that it is checked:
<?php namespace App\Http\Forms; use Rareloop\Lumberjack\Validation\AbstractForm; class ContactForm extends AbstractForm { /** * The validation rules for this form * * @type {Array} */ protected $rules = [ 'my-input-name' => '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:
<form method="" action=""> <input name="my-input-name" type="text"> {{ recaptcha() }} {% if errors['g-recaptcha-response'] %} {% for error in errors['g-recaptcha-response'] %} <p class="error">{{ error }}</p> {% endfor %} {% endif %} <button type-"submit">Submit</button> </form>