0

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();
3
  • stackoverflow.com/questions/27953858/… Commented Jun 10, 2017 at 23:15
  • I checked this link but me I want two differents forms but linked with the same entity. Commented Jun 11, 2017 at 17:11
  • if you want to two different form, use different object for User class. $user2 = New User(); And use in twig {{ form(form2) }} tag. Commented Jun 11, 2017 at 17:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.