-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.php
45 lines (33 loc) · 1001 Bytes
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
require_once 'src/Recaptcha.php';
require_once 'src/RecaptchaValidator.php';
use Fizz\Phalcon\Recaptcha;
use Fizz\Phalcon\RecaptchaValidator;
// setting up config & di
$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);
// creating form and recaptcha adding recaptcha to the form
$form = new Phalcon\Forms\Form;
$form->setDI($di);
$recaptcha = new Recaptcha('recaptcha');
$recaptcha->addValidator(new RecaptchaValidator(array(
'message' => "Are you human? (custom message)"
)));
$form->add($recaptcha);
// example of validation)
$post = array(
'g_recaptcha_response' => 'abzfoobar'
);
if ($form->isValid($post)) {
echo 'ok';
} else {
print_r($form->getMessages());
}