Google reCAPTCHA implementation for Nette Framework forms.
Branch | Composer | Nette | PHP | Readme |
---|---|---|---|---|
dev | ~3.4.0 | 3.0+ | ^7.2 | - |
latest | ~3.4.0 | 3.0+ | ^7.2 | - |
3.x | ~3.1.0 | 2.4 | ^7.1 | - |
2.x | ~2.1.0 | 2.4 | ^5.6 | README-2.x |
1.6.x | ~1.6.3 | 2.4 | ^5.6 | README-1.6 |
1.5.x | ~1.5.2 | 2.3 | ^5.4 | README-1.5 |
1.4.x | ~1.4.4 | 2.2 | ^5.4 | README-1.4 |
1.3.x | ~1.3.0 | 2.1 | ^5.4 | README-1.3 |
Add your site to the sitelist in reCAPTCHA administration.
The latest version is most suitable for Nette 2.4 and PHP >=5.6.
composer require contributte/recaptcha
extensions:
recaptcha: Contributte\ReCaptcha\DI\ReCaptchaExtension
recaptcha:
secretKey: ***
siteKey: ***
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());
}
}
<form n:name="myForm">
<div class="form-group">
<div n:name="recaptcha"></div>
</div>
</form>
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>
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());
}
}
Be sure to place this script before the closing tag of the body
element (</body>
).
Copy assets/invisibleRecaptcha.js and link it.
<script src="https://www.google.com/recaptcha/api.js?render=explicit"></script>
<script src="{$basePath}/assets/invisibleRecaptcha.js"></script>