Change the text of HTML 5 validation messages in Symfony 2

If you want to change the text of the HTML5 validation messages in your Symfony 2 project, you can do it one of two ways.

The controller method:

$builder->add('email', 'email',array(
    'attr'=>array('oninvalid'=>"setCustomValidity('Would you please enter a valid email?')")
));

Or, the Twig template method:

{{ form_row(form.email, { 'attr': {'oninvalid': "setCustomValidity('Please give me a nice email')"} }) }}

Very helpful, and very easy. Thanks to Carlos Granados at StackOverflow for getting me through that the first time.