Symfony2 Forms: changing the default prefix on form forms

I submit a form, and each widget has an ID: form_username, form_password, etc. and each corresponding label has a field for , as for = "form_username"

Is it possible to configure this pair of IDs for attributes as well? Because I show 2 forms on the page and the names of their fields collide ...

to change . Here is sample code where I want to customize the form name.

$form = $this->createFormBuilder($user, array('validation_groups' => array('registration'))) ->add('username', 'text') ->add('email', 'email') ->add('password', 'repeated', array('type' => 'password')) ->getform(); 
+4
source share
1 answer

You need to specify different names for the forms when creating them in the controller:

 $builder1 = $this->get('form.factory')->createNamedBuilder(new FooFormType(), 'foo1'); $builder2 = $this->get('form.factory')->createNamedBuilder(new FooFormType(), 'foo2'); 
+7
source

Source: https://habr.com/ru/post/1389359/


All Articles