leitsch / kirby-uniform-hcaptcha
Kirby 3 hCaptcha guard for the Uniform plugin
Installs: 35
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Type:kirby-plugin
Requires
- php: ^8.0
- getkirby/composer-installer: ^1.1
- mzur/kirby-uniform: ^5.0
README
A Kirby 3 plugin implementing a hCaptcha guard for the Uniform plugin.
Installation
Composer
Add the plugin to your project:
composer require leitsch/kirby-uniform-hcaptcha
Configuration
Set the configuration in your config.php
file:
return [ 'leitsch.uniform-hcaptcha.siteKey' => 'my-site-key', 'leitsch.uniform-hcaptcha.secretKey' => 'my-secret-key', ];
Usage
Template
You can use the provided helper function to embed the hCaptcha into your template:
<?= hcaptchaField() ?>
In order for hCaptcha to work, you need to provide the hCaptcha JavaScript file.
Use the helper function hcaptchaScript()
in your template.
Example
<form action="<?= $page->url() ?>" method="post"> <label for="name" class="required">Name</label> <input<?php if ($form->error('name')): ?> class="erroneous"<?php endif; ?> name="name" type="text" value="<?= $form->old('name') ?>"> <!-- ... --> <?= csrf_field() ?> <?= hcaptchaField() ?> <input type="submit" value="Submit"> </form> <?= hcaptchaScript() ?>
Controller
In your controller you can use the magic method hcaptchaGuard()
to enable the hCaptcha guard:
$form = new Form(/* ... */); if ($kirby->request()->is('POST')) { $form->hcaptchaGuard() ->emailAction(/* ... */); }
Credits
- Thanks to Lukas Dürrenberger for the Uniform reCAPTCHA Guard Plugin