diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 98e995b..1b72967 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ class Configuration implements ConfigurationInterface ->scalarNode('length')->defaultValue(5)->end() ->scalarNode('width')->defaultValue(120)->end() ->scalarNode('height')->defaultValue(40)->end() + ->scalarNode('keep_value')->defaultValue(true)->end() ->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end() ->scalarNode('as_file')->defaultValue(false)->end() ->scalarNode('image_folder')->defaultValue('captcha')->end() diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index 74269bb..6ff0a84 100755 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -45,6 +45,12 @@ class CaptchaType extends AbstractType */ protected $asFile; + /** + * Keep value between two requests ? + * @var boolean + */ + protected $keepValue; + /** * Charset used * @var string @@ -96,8 +102,9 @@ class CaptchaType extends AbstractType $this->width = $config['width']; $this->height = $config['height']; $this->length = $config['length']; - $this->asFile = $config['as_file']; $this->charset = $config['charset']; + $this->keepValue = $config['keep_value']; + $this->asFile = $config['as_file']; $this->imageFolder = $config['image_folder']; $this->webPath = $config['web_path']; $this->gcFreq = $config['gc_freq']; @@ -161,7 +168,7 @@ class CaptchaType extends AbstractType private function generateCaptchaValue() { - if (!$this->session->has($this->key)) { + if (!$this->keepValue || !$this->session->has($this->key)) { $value = ''; $chars = str_split($this->charset);