Questions tagged [symfony-forms]

The Symfony form component is a standalone library that can be used outside of Symfony projects.

Symfony form component provides tools for defining forms, rendering and mapping request data to related models. The component focuses on processing data to and from your client and application, whether that data be from a normal form post or from an API. Furthermore it provides integration with the Validation component.

Useful links

2507 questions
84
votes
2 answers

Add error to Symfony 2 form element

I check some validation in my controller. And I want to add error to specific element of my form on failure. My form: use Symfony\Component\Form\FormError; // ... $config = new Config(); $form = $this->createFormBuilder($config) …
Alex Pliutau
  • 19,672
  • 26
  • 103
  • 139
69
votes
12 answers

Symfony2 Setting a default choice field selection

I am creating a form in the following manner: $form = $this->createFormBuilder($breed) ->add('species', 'entity', array( 'class' => 'BFPEduBundle:Item', 'property' => 'name', …
Matt G
  • 1,291
  • 2
  • 11
  • 23
68
votes
1 answer

Difference between ObjectManager and EntityManager in Symfony2?

What's the difference between Doctrine\Common\Persistence\ObjectManager and Doctrine\ORM\EntityManager when using it in a custom form type? I can get the respository using both $this->em->getRepository() and $this->om->getRepository(). class…
gremo
  • 45,925
  • 68
  • 233
  • 380
62
votes
9 answers

Simple check if form field has errors in Twig template

In Twig template I check if a field has an error like this: {% if form.points.get('errors') is not empty %} Is there any method like: {% if form.points.hasErrors() %} to do it simpler? It's not a big difference, but if I can't do it easier why…
Dawid Ohia
  • 14,918
  • 21
  • 73
  • 92
33
votes
2 answers

Symfony 2 : Add a custom form element, not in an Entity

I work with Symfony2 and I would like to create a registration form. I don't want to use FOSUserBundle. So, I create an Entity Account (with fields : username, password, email...) and I create the form : $account = new Account(); $form =…
Thomas K
  • 1,015
  • 1
  • 14
  • 32
32
votes
5 answers

Symfony validate form with mapped false form fields

I've got a form with extra fields added with the option mapped to false. But when I try to validate my form, it won't pass indicating "this value is not valid" above these specific form fields. Isn't this option supposed to bypass validation? These…
kzrdt
  • 413
  • 2
  • 6
  • 11
31
votes
3 answers

How to pass parameter to FormType constructor from controller

In Symfony2.7 i was able to pass parameter to Form Type constructor directly from controller while creating the form, however in Symfony3 i'm not able to do it! Before in Symfony2.7 $postedBy = $this->getUser()->getFullname(); $form =…
Muzafar Ali
  • 1,162
  • 1
  • 11
  • 17
30
votes
1 answer

Apply class to Symfony2 Form Label

I'm attempting to set the class on a class on a form label using php templates. Here's my code: label($form['first_name'], 'First Name', array( 'attr' => array('class' => 'control-label') )) ?> But here's my…
jeremib
  • 721
  • 2
  • 7
  • 17
29
votes
3 answers

Symfony2 -> Twig -> Form -> Field -> Set rendered = true

i have a simple problem. I have a form with a field for example: $builder ->add('x') ->add('y') ->add('z') ; In my twig files i used multiple blocks and i want to stop render fields... I view the b.html.twig file! a.html.twig {% block…
PatrickB
  • 3,045
  • 5
  • 27
  • 53
26
votes
8 answers

Get translated country name from a 2 digit country code in Symfony2/Twig?

I'm using the Symfony2 country Field Type, it works well and country names are translated. I am storing the two-digit country code in the column country of my entity. How can I display the full, translated country name? This is how I added the field…
Polmonino
  • 3,422
  • 8
  • 34
  • 52
26
votes
1 answer

Description of Symfony2 form events?

This is the FormEvents class from Symfony2 repository on github. It's linked from the main article, How to Dynamically Generate Forms Using Form Events. Anyone konws exactly when these events are called in the flow? namespace…
Polmonino
  • 3,422
  • 8
  • 34
  • 52
26
votes
5 answers

Adding "help" messages to fields

I'm trying to add some help messages after each field in form in symfony2. I have read about one solution in official docs : http://symfony.com/doc/current/cookbook/form/form_customization.html#adding-help-messages But this solution makes little…
User Created Image
  • 1,102
  • 2
  • 17
  • 29
26
votes
1 answer

Symfony2 - form_start function customise in twig

Form helpers form_start and form_end are useful in twig: {{ form_start(form) }} {{ form_end(form) }} I can customise some parameters like the method or the action. But I need to customise others parameters like the class or add the…
Roberto Rizzi
  • 1,411
  • 5
  • 22
  • 36
26
votes
1 answer

Adding a field specific error from the controller in symfony2

I have some complex validation going on with my symfony form, and I need to be able to assign an error to a specific field from my controller. Right now, I have global errors working like this: $error = new formerror("There is an error with the…
MrGlass
  • 8,310
  • 17
  • 59
  • 87
25
votes
2 answers

Symfony form - Access Entity inside child entry Type in a CollectionType

I'm trying to access the entity for a given embedded form in the parent CollectionType inside FormBuilder: ParentType Class ParentType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { …
Nick
  • 2,632
  • 3
  • 31
  • 43
1
2 3
99 100