Remove caching of form name for key

This commit is contained in:
Jeremy Livingston 2012-12-03 18:54:39 -05:00
parent ba9e0818a5
commit 1437f0c7e0
1 changed files with 7 additions and 9 deletions

View File

@ -36,12 +36,6 @@ class CaptchaType extends AbstractType
*/
private $options = array();
/**
* Session key
* @var string
*/
private $key = 'captcha';
/**
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
* @param \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator
@ -60,9 +54,13 @@ class CaptchaType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->key = $builder->getForm()->getName();
$validator = new CaptchaValidator(
$this->session,
$builder->getForm()->getName(),
$options['invalid_message'],
$options['bypass_code']
);
$validator = new CaptchaValidator($this->session, $this->key, $options['invalid_message'], $options['bypass_code']);
$builder->addEventListener(FormEvents::POST_BIND, array($validator, 'validate'));
}
@ -76,7 +74,7 @@ class CaptchaType extends AbstractType
$view->vars = array_merge($view->vars, array(
'captcha_width' => $options['width'],
'captcha_height' => $options['height'],
'captcha_code' => $this->generator->getCaptchaCode($this->key, $options),
'captcha_code' => $this->generator->getCaptchaCode($form->getName(), $options),
'value' => '',
));
}