Symfony validator custom error message

If you need to customize your validator error messages, you can use the setMessage() function.
On your Form class (ex: /lib/form/doctrine/DemandeForm.class.php)

//sfValidatorInteger
$this->validatorSchema['produit_ean']->setMessage('invalid', 'ean should be integer');
$this->validatorSchema['produit_ean']->setMessage('min', 'ean must be at least %min%');
$this->validatorSchema['produit_ean']->setMessage('max', 'ean must be at least %max%');

//sfValidatorDate
$this->validatorSchema['date']->setMessage('bad_format', 'Format must be dd/mm/YYYY');
$this->validatorSchema['date']->setMessage('max', 'Date should be after than 01/01/2013');
$this->validatorSchema['date']->setMessage('min', 'Date should be before than 01/02/2013');

//required
$this->validatorSchema['date']->setMessage('required', 'Date is mandatory');

Leave a Reply