This is small component to provide Google Recaptcha functionality in Phalcon.
It uses phalcon DI. Be sure, you supply DI this correct recaptcha configuration.
Feel free to fork, clone this repo, or install via composer:
composer require fizzka/phalcon-recaptcha
There are 3 easy steps:
Setup up config & di (or ensure, you did this at application bootstrap ;) :
$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);
Create form and add recaptcha on it:
$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);
Validate form after submission:
//submitted data, ex
$post = array(
'g_recaptcha_response' => 'abzfoobar'
);
if ($form->isValid($post)) {
echo 'ok';
} else {
print_r($form->getMessages());
}
Full-working example @see example.php
MIT