Download the PHP package redcodede/captcha without Composer
On this page you can find all versions of the php package redcodede/captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redcodede/captcha
More information about redcodede/captcha
Files in redcodede/captcha
Package captcha
Short Description Human-friendly captcha addon for Statamic forms
License MIT
Informations about the package captcha
Captcha
Captcha is a Statamic addon that makes a classic captcha available for Statamic forms.
Features
This addon does:
- Provide Captcha Image
- Provide Tags to use in your Forms
Requirements
| Statamic | PHP |
|---|---|
| 5.x | 8.2+ |
| 6.x | 8.3+ |
The same release works on both major versions — the addon does not use any
Statamic APIs that changed between 5 and 6. It requires the gd, mbstring
and fileinfo PHP extensions (pulled in via gregwar/captcha).
Accessibility Notice
Please note that this captcha requires vision to solve. This captcha provides an image with a 4-character string that needs to be entered in the coresponding form field.
How to Install
You can search for this addon in the Tools > Addons section of the Statamic control panel and click install, or run the following command from your project root:
How to Use
1. Install the addon
Install the Captcha addon into your Statamic project as described in How to Install.
2. Add new validation rule
To use the Captcha in your form you need to add a new validation rule.
Do this by running php artisan make:rule VerifyCaptcha in your terminal.
The new rule should contain these methods:
public function passes($attribute, mixed $value): bool
{
try {
if (strtolower($_SESSION['phrase']) === strtolower($value)) {
Captcha::refreshCaptcha();
return true;
} else {
return false;
}
} catch(\Exception $e) {
return false;
}
}
public function message(): string { return '__(validation.verify_captcha)'; }
The message handles the error messages you may want to define in resources > lang.
Extending App Service Provider Extending the App Service Provider is no longer necessary.
4. Add your form field
Your form needs to contain a text form field with the validation rules required and captcha.
5. Include the captcha into your form template
The form template should include the {{ refresh_captcha }} tag to generate a new captcha on reloading the form to get a fresh one every time.
Your form field template should include an img tag with the src of {{ captcha_image }}.
This that will provide you with the image URL.
You can also add a button which will let the user generate another captcha image.
<button type="button" data-refresh-url="{{ captcha_refresh_url }}">generate new captcha image</button>
Now you should be all set to use the Captcha on your own Website.
Error Messages & Translations
The failure message of the captcha validation rule ships translated for:
de_DE · en_GB · es_ES · fr_FR · it_IT · nl_NL · pl_PL · pt_BR
Statamic uses the short lang code of a site (de) unless the site config sets a
full lang (de_DE), so each language is registered under both — you do not
have to configure anything. Sites in a language that is not listed fall back to
en.
Overriding a message
Either define captcha in your own lang/{locale}/validation.php — Laravel
checks the app's own files first:
Or publish the addon's files and edit them in place: