PHPackages                             drabek-digital/captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. drabek-digital/captcha

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

drabek-digital/captcha
======================

🤖 Nette Forms extension for Cloudflare Turnstile and hCaptcha integration

v2.0.4(3mo ago)41.2k↓27.1%1MITPHPPHP ^8.2CI passing

Since Jul 4Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/DrabekDigital/captcha)[ Packagist](https://packagist.org/packages/drabek-digital/captcha)[ RSS](/packages/drabek-digital-captcha/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (12)Versions (13)Used By (0)

Nette Captcha Extension
=======================

[](#nette-captcha-extension)

A comprehensive Nette Forms extension for integrating **Cloudflare Turnstile** and **hCaptcha** with your Nette applications.

Features
--------

[](#features)

- ✅ **Cloudflare Turnstile** integration (visible, managed, invisible modes)
- ✅ **hCaptcha** integration (visible mode)
- ✅ **PHP 8+** support
- ✅ **Server-side validation**
- ✅ **Flexible configuration**
- ✅ **Easy form integration**
- ✅ **Customizable themes and sizes**

Requirements
------------

[](#requirements)

- **PHP**: 8.2+
- **Nette Framework**: 3.0+ (limited by Nette forms 3.2 as min version)
- **Extensions**: `curl` or `allow_url_fopen` for server-side verification

Installation
------------

[](#installation)

Install via Composer:

```
composer require drabek-digital/captcha
```

Configuration
-------------

[](#configuration)

Register the extension in your `config.neon`:

```
extensions:
    captcha: DrabekDigital\Captcha\DI\CaptchaExtension

captcha:
    type: turnstile          # or hcaptcha
    secretKey: your-secret-key
    siteKey: your-site-key
    theme: auto              # light, dark, auto (optional)
    size: normal             # normal, compact (optional)
```

### Configuration Options

[](#configuration-options)

OptionTypeRequiredDefaultDescription`type`stringNo`turnstile`Captcha provider (`turnstile` or `hcaptcha`)`secretKey`string**Yes**-Your secret key from the captcha provider`siteKey`string**Yes**-Your site key from the captcha provider`verifyUrl`stringNo-Custom verification URL (uses default if not set)`theme`stringNo`auto`Theme: `light`, `dark`, or `auto``size`stringNo`normal`Size: `normal` or `compact`Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

First do not forget to render relevant JS script include in your Latte templates:

```
{* This will include Turnstile or hCaptcha JS code *}
{DrabekDigital\Captcha\Assets\CaptchaFrontend::getJavascriptStatic(\DrabekDigital\Captcha\Enums\CaptchaType::TURNSTILE)|noescape} {*  *}
{DrabekDigital\Captcha\Assets\CaptchaFrontend::getJavascriptStatic(\DrabekDigital\Captcha\Enums\CaptchaType::HCAPTCHA)|noescape} {*  *}

{* Include local JS to make forms validation (prevent submission when verification is missing) and to show managed states labels *}
{* ... or manually link /src/Assets/captcha-validation.js *}
{DrabekDigital\Captcha\Assets\CaptchaFrontend::getLocalJavascriptStatic()|noescape}
```

```
use Nette\Application\UI\Form;

$form = new Form;

// Simple captcha (required by default)
// The validator is automatically injected by the DI extension
$form->addCaptcha('captcha', 'Verify you are human');

// Handle form submission
$form->onSuccess[] = function($form) {
    $values = $form->getValues();
    // Process form...
};
```

### Advanced Usage

[](#advanced-usage)

```
// All supported method signatures:

// 1. Simple required visible captcha (Turnstile + hCaptcha)
$form->addCaptcha('captcha', 'Bot protection')
    ->setRequired(true);

// 2. Simple required visible captcha with custom required message (Turnstile + hCaptcha)
$form->addCaptcha('captcha', 'Bot protection')
    ->setRequired('Please verify you are human');

// 3. Simple managed captcha (only for Turnstile)
// The control + label will be rendered but the captcha can be shown or hidden based on Turnstile decision so therefore the JS code shows these messages
$form->addCaptcha('captcha', 'Bot protection')
    ->setManagedMessages('Check will be performed on background', Html::el('em')->setHtml('Check has been performed successfully.'));

// 4. Invisible captcha (only for Turnstile)
// The control + label will be hidden, the only thing that can be shown is required message.
$form->addCaptcha('captcha', 'Bot protection')
    ->setInvisible(true);
```

### Manual Instantiation (Advanced)

[](#manual-instantiation-advanced)

If you need to create the control manually (e.g., for testing):

```
use DrabekDigital\Captcha\CaptchaControl;
use DrabekDigital\Captcha\CaptchaValidator;
use DrabekDigital\Captcha\Enums\CaptchaType;

// Create validator manually
$validator = new CaptchaValidator('secret-key', 'turnstile');

// Create control (validator is the first mandatory parameter)
$captcha = new CaptchaControl($validator, 'Captcha', 'site-key', CaptchaType::TURNSTILE);
```

Limitations
-----------

[](#limitations)

- Only implicit rendering support for both providers (primarily due to reliability).
- For hCaptcha passive mode is not supported at all (no access).
- Custom verification endpoint was not tested.
- Other captcha providers may work but will need custom JS to ensure form validation to work.

License
-------

[](#license)

MIT License - see LICENSE file for details.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request, but better to consult via issues before large efforts.

Support
-------

[](#support)

For support, please create an issue on GitHub.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance82

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~42 days

Total

10

Last Release

92d ago

Major Versions

v1.0.1 → v2.0.02025-07-05

v1.0.2 → v2.0.12025-08-29

v1.0.4 → v2.0.22025-08-31

PHP version history (2 changes)v1.0.1PHP 7.4 - 8.2

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/475549?v=4)[Jan Drábek](/maintainers/repli2dev)[@repli2dev](https://github.com/repli2dev)

---

Top Contributors

[![repli2dev](https://avatars.githubusercontent.com/u/475549?v=4)](https://github.com/repli2dev "repli2dev (10 commits)")[![hrach](https://avatars.githubusercontent.com/u/284263?v=4)](https://github.com/hrach "hrach (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/drabek-digital-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/drabek-digital-captcha/health.svg)](https://phpackages.com/packages/drabek-digital-captcha)
```

###  Alternatives

[nette/schema

📐 Nette Schema: validating data structures against a given Schema.

1.0k336.4M125](/packages/nette-schema)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M450](/packages/nette-forms)[nette/nette

👪 Nette Framework - innovative framework for fast and easy development of secured web applications in PHP (metapackage)

1.6k2.8M335](/packages/nette-nette)[uestla/recaptcha-control

reCAPTCHA control for Nette Framework forms

26572.0k1](/packages/uestla-recaptcha-control)[smartemailing/types

Lightweight collection of handy PHP value objects

9368.7k1](/packages/smartemailing-types)[kdyby/validator

Integration of Symfony/Validator into Nette Framework

10128.1k4](/packages/kdyby-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
