I would like to use the same entity form but two times (to modify two differents properties of my entity). By example, I have a entity User, I create a form to modify the name and another to modify the first name on the same page (just an idiot example). If I submit the first form, it said me that I have extra fields (that is normal). I tried to change the action of the second form with setAction by example but i don't know how to retrieve the form in my controller action.
I started with this code :
$form = $this->createFormBuilder($user)
->add('name', TextareaType::class, array("required" => false))
->add('save', SubmitType::class, array('label' =>'Enregistrer'))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
return $this->redirectToRoute('myroute');
}
$form2 = $this->createFormBuilder($user)
->add('fname', TextareaType::class, array("required" => false))
->add('save', SubmitType::class, array('label' =>'Enregistrer'))
->getForm();
$user2 = New User();And use in twig{{ form(form2) }}tag.