0

I create a form in my controller without entity like following:

$defaultData = array('message' => 'Assign');
$form_assign = $this->createFormBuilder($defaultData)
  ->add('team', 'text', array('label' => 'Team'))
  ->add('create', 'button', array('label' => 'Create'))
  ->getForm();

Now when i render the form in my view with

{{ form(form_assign) }}

The name of the form is allways "form", like this:

<form name="form" method="post" action>

How do i change the name-attribute of the form? I work with Symfony version 2.4.2

(i have read this comment on a similar question and tried it out, but it didnt worked for me.)

Community
  • 1
  • 1
Fabian
  • 1,806
  • 5
  • 25
  • 40

1 Answers1

12

You can use the createNamedBuilder function :

$defaultData = array('message' => 'Assign');
$form_assign = $this->get('form.factory')->createNamedBuilder('your-custom-name', 'form', $defaultData, array())
    ->add('team', 'text', array('label' => 'Team'))
    ->add('create', 'button', array('label' => 'Create'))
    ->getForm();
ncrocfer
  • 2,542
  • 4
  • 33
  • 38
  • When I do this, with name `custom_name` I get a form named `custom_name` but then inputs with names like `form[first_name]` which does not compute :) – snakeoil Jul 07 '16 at 14:43