# Content

# Pre-installation

Add your site to the sitelist in reCAPTCHA administration (opens new window).

reCAPTCHA

# Installation

The latest version is most suitable for Nette 2.4 and PHP >=5.6.

composer require contributte/recaptcha
1

# Configuration

extensions:
	recaptcha: Contributte\ReCaptcha\DI\ReCaptchaExtension

recaptcha:
	secretKey: ***
	siteKey: ***
1
2
3
4
5
6

# Usage

use Nette\Application\UI\Form;

protected function createComponentForm()
{
	$form = new Form();

	$form->addReCaptcha('recaptcha', $label = 'Captcha')
		->setMessage('Are you a bot?');

	$form->addReCaptcha('recaptcha', $label = 'Captcha', $required = FALSE)
		->setMessage('Are you a bot?');

	$form->addReCaptcha('recaptcha', $label = 'Captcha', $required = TRUE, $message = 'Are you a bot?');

	$form->onSuccess[] = function($form) {
		dump($form->getValues());
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# Rendering

<form n:name="myForm">
    <div class="form-group">
        <div n:name="recaptcha"></div>
    </div>
</form>
1
2
3
4
5

Be sure to place this script before the closing tag of the body element (</body>).

<!-- re-Captcha -->
<script src='https://www.google.com/recaptcha/api.js'></script>
1
2

# Invisible

reCAPTCHA

# Usage

use Nette\Application\UI\Form;

protected function createComponentForm()
{
	$form = new Form();

	$form->addInvisibleReCaptcha('recaptcha')
		->setMessage('Are you a bot?');

	$form->addInvisibleReCaptcha('recaptcha', $required = FALSE)
		->setMessage('Are you a bot?');

	$form->addInvisibleReCaptcha('recaptcha', $required = TRUE, $message = 'Are you a bot?');

	$form->onSuccess[] = function($form) {
		dump($form->getValues());
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Be sure to place this script before the closing tag of the body element (</body>).

Copy assets/invisibleRecaptcha.js (opens new window) and link it.

<script src="https://www.google.com/recaptcha/api.js?render=explicit"></script>
<script src="{$basePath}/assets/invisibleRecaptcha.js"></script>
1
2