Simple check if form field has errors in Twig template
better way I found, is to use this kind of code {% if not form.vars.valid %} <div class=”alert alert-error”> {{ form_errors(form) }} </div> {% endif %}
better way I found, is to use this kind of code {% if not form.vars.valid %} <div class=”alert alert-error”> {{ form_errors(form) }} </div> {% endif %}
You can define the default value from the ‘data’ attribute. This is part of the Abstract “field” type (http://symfony.com/doc/2.0/reference/forms/types/field.html) $form = $this->createFormBuilder() ->add(‘status’, ‘choice’, array( ‘choices’ => array( 0 => ‘Published’, 1 => ‘Draft’ ), ‘data’ => 1 )) ->getForm(); In this example, ‘Draft’ would be set as the default selected value.
ObjectManager is an interface and EntityManager is its ORM implementation. It’s not the only implementation; for example, DocumentManager from MongoDB ODM implements it as well. ObjectManager provides only the common subset of all its implementations. If you want your form type to work with any ObjectManager implementation, then use it. This way you could switch … Read more
You can do $form->get(‘locationRadius’)->addError(new FormError(‘error message’)); As form elements are also of FormInterface type.