PHP code example of contributte / seznamcaptcha

1. Go to this page and download the library: Download contributte/seznamcaptcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

contributte / seznamcaptcha example snippets


use Nette\Application\UI\Form;

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

	$form->addCaptcha('captcha')
		->setRequired('Are you robot?');

	$form->addSubmit('send');

	$form->onSuccess[] = function (Form $form) {
		dump($form['captcha']);
	};

	return $form;
}

use Minetro\SeznamCaptcha\Forms\CaptchaHash;
use Minetro\SeznamCaptcha\Forms\CaptchaImage;
use Minetro\SeznamCaptcha\Forms\CaptchaInput;
use Minetro\SeznamCaptcha\Provider\CaptchaValidator;
use Minetro\SeznamCaptcha\Provider\ProviderFactory;
use Nette\Application\UI\Form;

/** @var ProviderFactory @inject */
public $providerFactory;

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

	$provider = $this->providerFactory->create();
	$form['image'] = new CaptchaImage('Captcha', $provider);
	$form['hash'] = new CaptchaHash($provider);
	$form['code'] = new CaptchaInput('Code');

	$form->addSubmit('send');

	$form->onValidate[] = function (Form $form) use ($provider) {
		$validator = new CaptchaValidator($provider);

		$hash = $form['hash']->getHttpHash();
		$code = $form['code']->getHttpCode();

		if ($validator->validate($code, $hash) !== TRUE) {
			$form->addError('Are you robot?');
		}
	};

	$form->onSuccess[] = function (Form $form) {
		dump($form);
	};

	return $form;
}