« Back to all articles

Silex Tip #1: How to quickly invalidate a form field in your controller

05 May 2013

You should be using custom constraints to validate your form fields, however there are some use-cases where you need to quickly invalidate in a controller. To do this it’s quite easy:

{% highlight php startinline %}

    $form->get('username')->addError(new \Symfony\Component\Form\FormError("This email is already in use"));

{% endhighlight %}

Ohhh, you're viewing this site in dark mode 👻 Spooky!