PHPackages                             xnukes/recaptcha-control - 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. xnukes/recaptcha-control

ActiveLibrary

xnukes/recaptcha-control
========================

reCAPTCHA control for Nette Framework forms

6.0.3(8y ago)01.5kMITPHPPHP &gt;=5.6.0

Since Jun 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/xnukes/ReCaptchaControl)[ Packagist](https://packagist.org/packages/xnukes/recaptcha-control)[ Docs](https://github.com/uestla/ReCaptchaControl)[ RSS](/packages/xnukes-recaptcha-control/feed)WikiDiscussions dev-master Synced today

READMEChangelog (3)Dependencies (9)Versions (27)Used By (0)

reCAPTCHA for Nette Framework
=============================

[](#recaptcha-for-nette-framework)

Adds the reCAPTCHA control to Nette Framework forms.

- [Official documentation](https://developers.google.com/recaptcha/)
- [Online demo](https://kesspess.cz/recaptcha/)
- [Nette forum thread (CZE)](http://forum.nette.org/cs/21770-nova-recaptcha-pro-formulare)

Documentation
-------------

[](#documentation)

1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Usage](#usage)
4. [Requester](#requester)
5. [AJAX](#ajax)
6. [Invisible reCAPTCHA](#invisible-recaptcha)
7. [Testing](#testing)

### Installation

[](#installation)

For easy installation use [Composer](https://getcomposer.org/):

```
composer require uestla/recaptcha-control

```

Also don't forget to include the official JavaScript library:

```

```

Are you using AJAX? Then you may want to use library asset instead - [see more](#ajax).

### Configuration

[](#configuration)

To be able to use the reCAPTCHA control in your forms just register the DI extension in your `config.neon`:

```
extensions:
	recaptcha: ReCaptchaControl\DI\Extension

recaptcha:
	# required
	siteKey: ''
	secretKey: ''

	# optional
	methodName: 'addReCaptcha'
	requester: ReCaptchaControl\Http\Requester\CurlRequester
```

**Parameters:**

ParameterTypeDefault valueRequiredMeaning`siteKey`string~YESThe site key you obtain in your [Google Account](https://www.google.com/recaptcha/admin)`secretKey`string~YESThe secret key you obtain in your [Google Account](https://www.google.com/recaptcha/admin)`methodName`string"addReCaptcha"NOExtension method name you'll be calling upon your forms to add the control, e.g. `$form->addReCaptcha(...)``requester`string["CurlRequester"](src/ReCaptchaControl/Http/Requester/CurlRequester.php)NOName of the class or service which sends requests to the Google validation API. The default `CurlRequester` needs PHP cURL extension to run properly. [Read more about requesters here](#requester).### Usage

[](#usage)

#### Form

[](#form)

To actually add reCAPTCHA to your form just call

```
$form->addReCaptcha(
	'captcha', // control name
	'reCAPTCHA for you', // label
	"Please prove you're not a robot." // error message
);
```

Please note that the validation rule is added automatically so you don't need to call any `addRule()` at all.

#### Template

[](#template)

You can then render the control in your Latte template using both macro and `n:attr` approach:

```

	{* n:attr *}

	{* or macro *}
	{input captcha}

```

And there she goes! :-)

[![reCAPTCHA](https://camo.githubusercontent.com/40bb866811cdd5e524492985f570536af284b23f8cf704af499595c6d00273c0/687474703a2f2f692e696d6775722e636f6d2f73364d44716d562e706e67)](https://camo.githubusercontent.com/40bb866811cdd5e524492985f570536af284b23f8cf704af499595c6d00273c0/687474703a2f2f692e696d6775722e636f6d2f73364d44716d562e706e67)

### Requester

[](#requester)

Requester is a layer for sending HTTP requests. It comes handy when your production environment does not meet the default requirements (cURL extension etc.).

You can change the default requester by setting the `requester` key in [configuration](#configuration). The value can be either a class name or a name of another service (see details below).

1. #### CurlRequester

    [](#curlrequester)

    This is the default one since `requester` value is optional in configuration.

    It uses PHP cURL extension. If you want to set any [CURLOPT\_\*](http://php.net/manual/en/function.curl-setopt.php) value for the requests you have to create the service aside and pass these options to the constructor:

    ```
    recaptcha:
    	...
    	requester: @curlRequester

    services:
    	curlRequester:
    		class: ReCaptchaControl\Http\Requester\CurlRequester
    		arguments:
    			-
    				CURLOPT_CAINFO: %appDir%/res/cacert.pem
    				CURLOPT_SSL_VERIFYPEER: false # Verify SSL OFF
    				CURLOPT_USERAGENT: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36'
    ```

    As you can see in the example it is possible to use all CURLOPT\_\* constants as string keys (they are [converted internally](src/ReCaptchaControl/Http/Requester/CurlRequester.php#L30)).
2. #### SimpleRequester

    [](#simplerequester)

    Calls `file_get_contents()` with stream context.

    ```
    recaptcha:
    	...
    	requester: ReCaptchaControl\Http\Requester\SimpleRequester
    ```
3. #### GuzzleRequester

    [](#guzzlerequester)

    If you're already using the [Guzzle HTTP Client](https://github.com/guzzle/guzzle/) in your application, this requester may come handy:

    ```
    recaptcha:
    	...
    	requester: ReCaptchaControl\Http\Requester\GuzzleRequester

    services:
    	- Guzzle\Http\Client # will be autowired to the GuzzleRequester constructor
    ```

    If you're using multiple clients it is better to define the requester as a service aside:

    ```
    recaptcha:
    	...
    	requester: @guzzleRequester

    services:
    	guzzleRequester: ReCaptchaControl\Http\Requester\GuzzleRequester(@primaryGuzzleHttpClient)

    	primaryGuzzleHttpClient: Guzzle\Http\Client
    	secondaryGuzzleHttpClient: Guzzle\Http\Client
    ```
4. #### Custom requester

    [](#custom-requester)

    You can also implement your own requester. Just make sure it implements the [ReCaptchaControl\\Http\\Requester\\IRequester](src/ReCaptchaControl/Http/Requester/IRequester.php) interface.

    It basically requires a single `public function post($url, array $values = [])` method which takes the URL as a string, performs a HTTP POST request with given `$values` and returns body of the response as a string or FALSE on failure.

    You can then use it the same way as above:

    ```
    recaptcha:
    	requester: MyRequesterClass
    ```

    or when you have some dependencies:

    ```
    recaptcha:
    	requester: @myRequester

    services:
    	myRequester:
    		factory: MyRequesterClass( ... )
    		...
    ```

### AJAX

[](#ajax)

When a snippet containing reCAPTCHA control gets updated, the reCAPTCHA itself needs to be re-rendered.

If you're using the [nette.ajax.js](https://github.com/vojtech-dobes/nette.ajax.js), you may want to use the [assets/recaptcha.ajax.js](assets/recaptcha.ajax.js) script.

You can install it via `bower`:

```
bower install

```

IMPORTANT: The [recaptcha.ajax.js](assets/recaptcha.ajax.js) script loads the official JavaScript library because it needs to render the reCATPCHAs [explicitely](https://developers.google.com/recaptcha/docs/display#explicit_render). So please be careful not to loaded by yourself as well.

### Invisible reCAPTCHA

[](#invisible-recaptcha)

You can also use this library for [Invisible reCAPTCHA](https://developers.google.com/recaptcha/docs/invisible). The backend part stays the same so it only needs proper configuration in the frontend. To see it in action you can visit  and the code in [tests](tests/manual/app/presenters/templates/Test/invisible.latte).

### Testing

[](#testing)

You may have noticed the [tests/manual](tests/manual) directory. Its content is actualy live at .

To get it to work on your local machine, do following:

1. copy `app/config/config.local.neon.template` to `app/config/config.local.neon`
2. fill reCAPTCHA keys properly in `app/config/config.local.neon`
3. run `composer install`
4. run `bower install`

After that you should be able to run it via your local web server.

The form definitions are in [TestPresenter](tests/manual/app/presenters/TestPresenter.php).

Individual example templates are located in [presenters/templates](tests/manual/app/presenters/templates) directory.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 91.3% 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 ~44 days

Recently: every ~37 days

Total

25

Last Release

3276d ago

Major Versions

2.0.8 → 3.0.02016-03-03

2.0.10 → 3.0.12016-07-02

3.0.2 → 4.0.02016-07-03

4.0.4 → 5.0.02016-12-23

5.0.0 → 6.0.02017-01-24

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

2.0.10PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/657decbe136a1fb608d988aceea09a3d35152a6af1aaf43728be3a7569bfda3a?d=identicon)[xnukes](/maintainers/xnukes)

---

Top Contributors

[![uestla](https://avatars.githubusercontent.com/u/373888?v=4)](https://github.com/uestla "uestla (105 commits)")[![xnukes](https://avatars.githubusercontent.com/u/20656316?v=4)](https://github.com/xnukes "xnukes (4 commits)")[![trejjam](https://avatars.githubusercontent.com/u/3594540?v=4)](https://github.com/trejjam "trejjam (3 commits)")[![hranicka](https://avatars.githubusercontent.com/u/3034538?v=4)](https://github.com/hranicka "hranicka (1 commits)")[![o5](https://avatars.githubusercontent.com/u/218562?v=4)](https://github.com/o5 "o5 (1 commits)")[![vojtech-dobes](https://avatars.githubusercontent.com/u/415925?v=4)](https://github.com/vojtech-dobes "vojtech-dobes (1 commits)")

---

Tags

netterecaptchaForms

### Embed Badge

![Health badge](/badges/xnukes-recaptcha-control/health.svg)

```
[![Health](https://phpackages.com/badges/xnukes-recaptcha-control/health.svg)](https://phpackages.com/packages/xnukes-recaptcha-control)
```

###  Alternatives

[uestla/recaptcha-control

reCAPTCHA control for Nette Framework forms

26572.0k1](/packages/uestla-recaptcha-control)[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/application

🏆 Nette Application: a full-stack component-based MVC kernel for PHP that helps you write powerful and modern web applications. Write less, have cleaner code and your work will bring you joy.

44615.4M983](/packages/nette-application)[contributte/recaptcha

Google reCAPTCHA for Nette - Forms

421.3M4](/packages/contributte-recaptcha)[kdyby/forms-replicator

Nette forms container replicator aka addDynamic

32997.7k6](/packages/kdyby-forms-replicator)[contributte/forms-bootstrap

Nette extension for Bootstrap forms

211.1M4](/packages/contributte-forms-bootstrap)

PHPackages © 2026

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