Add invalid_message configuration option
This commit is contained in:
parent
a204bdc3f9
commit
8d54bfd598
|
@ -31,6 +31,7 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('gc_freq')->defaultValue(100)->end()
|
||||
->scalarNode('expiration')->defaultValue(60)->end()
|
||||
->scalarNode('quality')->defaultValue(15)->end()
|
||||
->scalarNode('invalid_message')->defaultValue('Bad code value')->end()
|
||||
->end()
|
||||
;
|
||||
return $treeBuilder;
|
||||
|
|
|
@ -125,6 +125,7 @@ You can define the following type option :
|
|||
* **web_path**: absolute path to public web folder (default="%kernel.root_dir%/../web")
|
||||
* **gc_freq**: frequency of garbage collection in fractions of 1 (default=100)
|
||||
* **expiration**: maximum lifetime of captcha image files in minutes (default=60)
|
||||
* **invalid_message**: error message displayed when an non-matching code is submitted (default="Bad code value")
|
||||
|
||||
Example :
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class CaptchaType extends AbstractType
|
|||
$this->key = $builder->getForm()->getName();
|
||||
|
||||
$builder->addValidator(
|
||||
new CaptchaValidator($this->session, $this->key)
|
||||
new CaptchaValidator($this->session, $this->key, $options['invalid_message'])
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,16 @@ class CaptchaValidator implements FormValidatorInterface
|
|||
*/
|
||||
private $key;
|
||||
|
||||
public function __construct(Session $session, $key)
|
||||
/**
|
||||
* Error message text for non-matching submissions
|
||||
*/
|
||||
private $invalidMessage;
|
||||
|
||||
public function __construct(Session $session, $key, $invalidMessage)
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->key = $key;
|
||||
$this->invalidMessage = $invalidMessage;
|
||||
}
|
||||
|
||||
public function validate(FormInterface $form)
|
||||
|
@ -37,7 +43,7 @@ class CaptchaValidator implements FormValidatorInterface
|
|||
|
||||
if (!($code && $excepted_code && is_string($code) && is_string($excepted_code)
|
||||
&& $this->niceize($code) == $this->niceize($excepted_code))) {
|
||||
$form->addError(new FormError('Bad code value'));
|
||||
$form->addError(new FormError($this->invalidMessage));
|
||||
}
|
||||
|
||||
$this->session->remove($this->key);
|
||||
|
|
Loading…
Reference in New Issue