PHP code example of erwane / cakephp-hcaptcha

1. Go to this page and download the library: Download erwane/cakephp-hcaptcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

erwane / cakephp-hcaptcha example snippets


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

    // 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,
    ],

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

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

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']);
}