The captcha integration requires two parts of configuration:
Add the captcha configuration to your form's blueprint:
# site/blueprints/emails/contact-form.yml
captcha:
frontend:
snippet: captcha/custom # Path to your captcha snippet
fieldname: captcha-field # Name of the form field
options:
# Optional parameters for your captcha implementation
error_messages:
missing:
en: "Please complete the captcha"
de: "Bitte füllen Sie das Captcha aus"
invalid:
en: "Invalid captcha response"
de: "Ungültige Captcha-Antwort"
Register a validation callback in your site's config:
// site/config/config.php
return [
'philippoehrlein.kirby-email-manager' => [
'captcha' => [
'callback' => function($response, $config) {
// Your validation logic here
// $response: The user's input
// $config: The captcha configuration from your blueprint
return true; // or false based on validation
}
]
]
];
| Name | Type | Default | Description |
|---|---|---|---|
| $config |
object
|
– |
The complete captcha configuration from your blueprint |
| $response |
object
|
– |
The user's input from the form field |
Create a snippet for your captcha that follows the plugin's structure:
// site/snippets/captcha/custom.php
<?php
use KirbyEmailManager\Helpers\FormHelper;
// Your captcha generation logic here
?>
<div class="<?= FormHelper::getClassName('field', $config) ?>">
<label class="<?= FormHelper::getClassName('label', $config) ?>">
<!-- Your captcha challenge -->
</label>
<input type="text"
name="<?= $fieldName ?>"
class="<?= FormHelper::getClassName('input', $config) ?>"
required>
<?php if (isset($error)): ?>
<p class="<?= FormHelper::getClassName('error', $config) ?>">
<?= $error ?>
</p>
<?php endif ?>
</div>
The plugin will automatically: