O
O
ol sm2017-08-13 14:34:54
symfony
ol sm, 2017-08-13 14:34:54

Why is the form data not being submitted?

Good afternoon, dear ones.
Tell me, please, why in this situation, the data from the IndividualUserType form is not transferred?

public function createAction(Request $request)
    {
        $user = new User();

        $individualUser = new IndividualUser();

        $iform = $this->createForm('BackendBundle\Form\IndividualUserType', $individualUser);

        $iform->handleRequest($request);

        $form = $this->createForm('BackendBundle\Form\UserType', $user);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($user);
            $em->flush();
            $em->persist($individualUser);
            $em->flush();

            $this->addFlash(
                'notice',
                'Запись была добавлена в БД'
            );
            return $this->redirectToRoute('cli_settings_user_index');
        }
        return $this->render('BackendBundle:User:create.html.twig',array(
            'form' => $form->createView(),
            'iform' => $iform->createView()
        ));
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2017-08-13
@ol_efk

You cannot take and submit two different forms at once in one request. Please check the logic. Well, you can say more precisely by seeing how you draw them in twig (or whatever you have there).
Why don't you make a combined type containing both the user's data and the user's individual? It is done in a trivial way. And relieves of the above hemorrhoids.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question