So I have my controller action similar to this
$task1 = new Task();
$form1 = $this->createForm(new MyForm(), $task1);
$task2 = new Task();
$form2 = $this
EDIT: Do not do that! See this instead: http://stackoverflow.com/a/36557060/6268862
In Symfony 3.0:
class MyCustomFormType extends AbstractType
{
private $formCount;
public function __construct()
{
$this->formCount = 0;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
++$this->formCount;
// Build your form...
}
public function getBlockPrefix()
{
return parent::getBlockPrefix().'_'.$this->formCount;
}
}
Now the first instance of the form on the page will have "my_custom_form_0" as its name (same for fields' names and IDs), the second one "my_custom_form_1", ...