Adding option "humanity" (fixes #40)

This commit is contained in:
Gregwar
2012-12-04 12:20:23 +01:00
parent 3794a12e80
commit 11fe650bde
5 changed files with 40 additions and 2 deletions

View File

@ -66,7 +66,8 @@ class CaptchaType extends AbstractType
$this->session,
$this->key,
$options['invalid_message'],
$options['bypass_code']
$options['bypass_code'],
$options['humanity']
);
$builder->addEventListener(FormEvents::POST_BIND, array($validator, 'validate'));
@ -79,11 +80,21 @@ class CaptchaType extends AbstractType
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$isHuman = false;
if ($options['humanity'] > 0) {
$humanityKey = $this->key.'_humanity';
if ($this->session->get($humanityKey, 0) > 0) {
$isHuman = true;
}
}
$view->vars = array_merge($view->vars, array(
'captcha_width' => $options['width'],
'captcha_height' => $options['height'],
'captcha_code' => $this->generator->getCaptchaCode($this->key, $options),
'value' => '',
'is_human' => $isHuman
));
}