erwane/cakephp-hcaptcha

HCaptcha plugin for CakePHP

Installs: 45

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

1.0.0 2021-04-11 15:40 UTC

This package is auto-updated.

Last update: 2021-10-11 17:24:30 UTC


README

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

Add the captcha to your form

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

In your form validation, could be a model or modelless form, add Validation provider and use hcaptcha 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']);
}