Create a form from a class in a controller

# Create a form from a form class with a default name #

$form = $this->createForm(TaskForm::class, $data, array(
'action' => $this->generateUrl('target_route'),
'method' => 'GET',
));

# Create a form from a form class with a non-default name #

$form = $this->container->get('form.factory')
->createNamed('form1', TaskForm::class, $data, array(
'action' => $this->generateUrl('target_route'),
'method' => 'GET',
));
Comments