erwane/cakephp-hcaptcha

HCaptcha plugin for CakePHP

Installs: 84

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

1.1.1 2022-08-17 16:41 UTC

This package is auto-updated.

Last update: 2022-09-17 16:50:10 UTC


README

Build Status codecov Total Downloads Software License

Installation

With composer

composer require erwane/cakephp-hcaptcha

Load plugin in your src/Application::bootstrap()

    public function bootstrap(): void
    {
        $this->addPlugin('HCaptcha');
    }

Configuration

In your config/app.php, insert this default values:

    // If you use .env file:
    'HCaptcha' => [
        'key' => env('HCAPTCHA_KEY'),
        'secret' => env('HCAPTCHA_SECRET'),
    ],

    // If you use config/app_local.php
    'HCaptcha' => [
        'key' => null,
        'secret' => null,
    ],

HCaptcha key and secret can be found in your HCaptcha dashboard

Usage

In your templates

Add the captcha to your form

<?= $this->Form->control('h-captcha-response', ['type' => 'hcaptcha']) ?>

You can pass options to hCaptcha.

<?= $this->Form->control('h-captcha-response', [
    'type' => 'hcaptcha',
    'lang' => 'fr_FR',
    'onload' => 'myFunction',
    'render' => 'explicit',
    'recaptchacompat' => false,
]) ?>

Validation

In your Model or Form validation, add hCaptcha validation provider and define your rule.

use Cake\Validation\Validator;

public function validationDefault(Validator $validator): Validator
{
    $validator->setProvider('HCaptcha', '\HCaptcha\Validation');

    return parent::validationDefault($validator)
        ->add('h-captcha-response', 'hcaptcha', ['provider' => 'HCaptcha', 'rule' => 'hcaptcha']);
}