vottuscode/hcaptcha

hCaptcha for Nette Forms

1.0.1 2020-05-18 15:43 UTC

This package is auto-updated.

Last update: 2020-05-18 15:44:28 UTC


README

hCaptcha implementation for Nette Framework forms.

Forked from contributte/reCAPTCHA

Pre-installation

Add your site to the site list in the hCaptcha dashboard.

hCaptcha in action

hCaptcha in action

Installation

The latest version is most suitable for Nette 3.0 and PHP >=7.1.

composer require vottuscode/hcaptcha

Configuration

extensions:
    recaptcha: Contributte\ReCaptcha\DI\ReCaptchaExtension

recaptcha:
    secretKey: "your_hcaptcha_secret_key"
    siteKey: your_hcaptcha_site_key

(Be sure to include quotes for the secretKey)

Usage

(It is the same as hCaptcha, there is no change whatsoever in classes to prevent BC breaks )

use Nette\Application\UI\Form;

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

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

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

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

    $form->onSuccess[] = function($form) {
        Debugger::barDump($form->getValues());
    };
}

Rendering

<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://hcaptcha.com/1/api.js" async defer></script>