Search

Friends

Atomspheric CO2 (PPM)

Archives

Blather

Uptime verified by Wormly.com

21 December 2011

Symfony2 invalid type messages

Symfony2 will automatically add validation to entity fields ensuring that values match the database type. For instance, If you try to set an alpha character on a DECIMAL column you will get "This value is not valid" along with other constraint violations. If you manually add a Type Constraint you'll end up with a largely duplicate assertion. However, if you want to set the message on the default constraint, you can't do it in the entity itself. You have to do it in the form class.

$builder->add('amount', 'money', array(
  'label' => 'Default Price', 
  'invalid_message' => 'Price must be a number'
));

I couldn't find that documented anywhere, but it works.

Comments

  1. […] this […]

    Symfony 2 – Validate a domain with NotBlank & Type constraints | Zhanel / 7:17pm / 23 November 2014

Leave a comment

Markdown

0.106 seconds