Contributte Wordcha
Question-based captcha for Nette Framework / Forms.
# Content
# Setup
Require package
composer require contributte/wordcha
1
Register extension
extensions:
wordcha: Contributte\Wordcha\DI\WordchaExtension
1
2
2
# Configuration
At the beginning you should pick the right datasource.
# Numeric datasource
wordcha:
datasource: numeric
1
2
2
# Question datasource
wordcha:
datasource: questions
questions:
"Question a?": "a"
"Question b?": "b"
1
2
3
4
5
2
3
4
5
# Form
use Nette\Application\UI\Form;
protected function createComponentForm()
{
$form = new Form();
$form->addWordcha('wordcha')
->getQuestion()
->setRequired('Please answer antispam question');
$form->addSubmit('send');
$form->onValidate[] = function (Form $form) {
if ($form['wordcha']->verify() !== TRUE) {
$form->addError('Are you robot?');
}
};
$form->onSuccess[] = function (Form $form) {
dump($form['wordcha']);
};
return $form;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24