PHP code example of fizzka / phalcon-recaptcha

1. Go to this page and download the library: Download fizzka/phalcon-recaptcha 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/ */

    

fizzka / phalcon-recaptcha example snippets


$config = new Phalcon\Config(array(
	"recaptcha" => array(
		'publicKey' => '[...your pub key goes here...]',
		'secretKey' => '[...your priv key goes here...]',
		'jsApiUrl' => 'https://www.google.com/recaptcha/api.js',
		'verifyUrl' => 'https://www.google.com/recaptcha/api/siteverify',
	)
));

$di = new Phalcon\DI\FactoryDefault();
$di->set('config', $config);

$form = new Phalcon\Forms\Form;
$form->setDI($di);

$recaptcha = new Fizz\Phalcon\Recaptcha('recaptcha');
$recaptcha->addValidator(new Fizz\Phalcon\RecaptchaValidator(array(
	'message' => "Are you human? (custom message)"
)));

$form->add($recaptcha);

//submitted data, ex
$post = array(
	'g_recaptcha_response' => 'abzfoobar'
);

if ($form->isValid($post)) {
	echo 'ok';
} else {
	print_r($form->getMessages());
}