Skip to content

Latest commit

 

History

History
73 lines (55 loc) · 1.42 KB

README-1.5.md

File metadata and controls

73 lines (55 loc) · 1.42 KB

reCAPTCHA 1.5.x

Installation

This version is suitable for Nette 2.3.

composer require minetro/recaptcha:~1.5.2

Configuration

# reCAPTCHA
parameters:
	reCAPTCHA:
		siteKey: ***key**
		secretKey: ***key**
services:
	reCAPTCHA.validator:
		class: Minetro\Forms\reCAPTCHA\ReCaptchaValidator
		implement: Minetro\Forms\reCAPTCHA\IReCaptchaValidatorFactory
		arguments: [%reCAPTCHA.secretKey%]

	reCAPTCHA.holder:
		factory: Minetro\Forms\reCAPTCHA\ReCaptchaHolder::factory(%reCAPTCHA.siteKey%)
		tags: [run]

Usage

use Minetro\Forms\reCAPTCHA\ReCaptchaField;
use Minetro\Forms\reCAPTCHA\IReCaptchaValidatorFactory;
use Nette\Application\UI\Form;

/** @var IReCaptchaValidatorFactory @inject */
public $reCaptchaValidatorFactory;

/** @var string */
private $siteKey;

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

	$form['recaptcha'] = $recaptcha = new ReCaptchaField($this->siteKey, $label = NULL);

	$validator = $this->reCaptchaValidatorFactory->create();
	$recaptcha->addRule([$validator, 'validateControl'], 'You`re bot!');
}

Rendering

<form n:name="myForm">
    <div class="form-group">
        <label n:name="captcha" class="required">Captcha</label>
        <div n:name="captcha"></div>
    </div>
</form>

Place this script before </body> element.

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