diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 1342186..0b438cb 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -28,6 +28,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end()
->scalarNode('as_file')->defaultValue(false)->end()
->scalarNode('as_url')->defaultValue(false)->end()
+ ->scalarNode('reload')->defaultValue(false)->end()
->scalarNode('image_folder')->defaultValue('captcha')->end()
->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end()
->scalarNode('gc_freq')->defaultValue(100)->end()
diff --git a/DependencyInjection/GregwarCaptchaExtension.php b/DependencyInjection/GregwarCaptchaExtension.php
index 83f4ddb..75b7246 100755
--- a/DependencyInjection/GregwarCaptchaExtension.php
+++ b/DependencyInjection/GregwarCaptchaExtension.php
@@ -33,6 +33,10 @@ class GregwarCaptchaExtension extends Extension
$container->setParameter('gregwar_captcha.config.expiration', $config['expiration']);
$container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']);
+ if ($config['reload'] && !$config['as_url']) {
+ throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
+ }
+
$resources = $container->getParameter('twig.form.resources');
$container->setParameter('twig.form.resources', array_merge(array('GregwarCaptchaBundle::captcha.html.twig'), $resources));
}
diff --git a/README.md b/README.md
index 88a3084..880cbff 100644
--- a/README.md
+++ b/README.md
@@ -133,6 +133,7 @@ You can define the following configuration options globally or on the CaptchaTyp
* **invalid_message**: error message displayed when an non-matching code is submitted (default="Bad code value", see the translation section for more information)
* **bypass_code**: code that will always validate the captcha (default=null)
* **whitelist_key**: the session key to use for keep the session keys that can be used for captcha storage, when using as_url (default=captcha_whitelist_key)
+* **reload**: adds a link to reload the code
* **humanity**: number of extra forms that the user can submit after a correct validation, if set to a value different of 0, only 1 over (1+humanity) forms will contain a CAPTCHA (default=0, i.e each form will contain the CAPTCHA)
Example :
diff --git a/Resources/translations/gregwar_captcha.fr.yml b/Resources/translations/gregwar_captcha.fr.yml
new file mode 100644
index 0000000..bb4fc36
--- /dev/null
+++ b/Resources/translations/gregwar_captcha.fr.yml
@@ -0,0 +1 @@
+Renew: Renouveler
diff --git a/Resources/views/captcha.html.twig b/Resources/views/captcha.html.twig
index e7ac34d..7871dae 100644
--- a/Resources/views/captcha.html.twig
+++ b/Resources/views/captcha.html.twig
@@ -3,7 +3,16 @@
-
{% else %}
{% spaceless %}
-
+
+ {% if reload %}
+
+ {{ 'Renew'|trans({}, 'gregwar_captcha') }}
+ {% endif %}
{{ form_widget(form) }}
{% endspaceless %}
{% endif %}
diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php
index 78ba23c..101b62a 100644
--- a/Type/CaptchaType.php
+++ b/Type/CaptchaType.php
@@ -92,6 +92,8 @@ class CaptchaType extends AbstractType
$view->vars = array_merge($view->vars, array(
'captcha_width' => $options['width'],
'captcha_height' => $options['height'],
+ 'reload' => $options['reload'],
+ 'id' => uniqid('captcha_'),
'captcha_code' => $this->generator->getCaptchaCode($this->key, $options),
'value' => '',
'is_human' => $isHuman