I have a problem with multiple symfony (include).
I have several articles on one page, the user can add comments for each article. I would like to show a form to add a comment.
My problem is this: when I submit a comment form, Symfony does not save the information in the database (without an error message).
I tried to add a class to change the name of my form, but this is the same.
My form action in the controller (quiz call for each article)
public function formAction($post_id, Request $request) { $user = $this->getUser(); $em = $this->getDoctrine()->getManager(); $post = $em->getRepository('AppBundle:Post')->find($post_id); $comment = new Comment(); $comment -> setPost($post); $comment -> setAuthor($user); $form_comment = $this->createForm(CommentType::class, $comment); $form_comment->handleRequest($request); if ($form_comment->isSubmitted()) { $em = $this->getDoctrine()->getManager(); $em->persist($comment); $em->flush(); $request->getSession()->getFlashBag()->add('msg_success', 'Votre contribution a bien รฉtรฉ ajoutรฉe'); } return $this->render('account/form-comment.html.twig', array( 'form_comment' => $form_comment->createView(), 'post_id' => $post_id )); }
Get name in form type (for unique identifier)
public function getName() { return self::NAME . '_' . uniqid(); }
source share