From 458e7cafef715da650ac4da7ce190a6299c26d78 Mon Sep 17 00:00:00 2001 From: Piotr Antosik Date: Mon, 21 Jul 2014 14:46:14 +0200 Subject: [PATCH] fix multiple captcha on page --- Type/CaptchaType.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index 3a18eb3..7991ea2 100644 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -26,12 +26,6 @@ class CaptchaType extends AbstractType */ protected $session; - /** - * The session key - * @var string - */ - protected $key = null; - /** * @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator */ @@ -67,12 +61,10 @@ class CaptchaType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { - $this->key = 'gcb_'.$builder->getForm()->getName(); - $validator = new CaptchaValidator( $this->translator, $this->session, - $this->key, + sprintf('gcp_%s', $builder->getForm()->getName()), $options['invalid_message'], $options['bypass_code'], $options['humanity'] @@ -94,21 +86,22 @@ class CaptchaType extends AbstractType throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'); } + $key = sprintf('gcp_%s', $form->getName()); + if ($options['humanity'] > 0) { - $humanityKey = $this->key.'_humanity'; + $humanityKey = sprintf('%s_humanity', $key); if ($this->session->get($humanityKey, 0) > 0) { $isHuman = true; } } if ($options['as_url']) { - $key = $this->key; $keys = $this->session->get($options['whitelist_key'], array()); if (!in_array($key, $keys)) { $keys[] = $key; } $this->session->set($options['whitelist_key'], $keys); - $options['session_key'] = $this->key; + $options['session_key'] = $key; } $view->vars = array_merge($view->vars, array( @@ -126,7 +119,7 @@ class CaptchaType extends AbstractType $persistOptions[$key] = $options[$key]; } - $this->session->set($this->key, $persistOptions); + $this->session->set($key, $persistOptions); } /**