erwane / cakephp-hcaptcha
HCaptcha plugin for CakePHP
Installs: 588
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: ^7.2 | ^8.0
- ext-intl: *
- cakephp/cakephp: ^4.0
Requires (Dev)
- cakephp/cakephp-codesniffer: ^4.0
- php-parallel-lint/php-parallel-lint: ^1.0
- phpro/grumphp: ^v0.19 | ^v1.0
- phpunit/phpunit: ^8.0 | ^9.0
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
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']); }