Comment Blog creating not working symfony

Hello i was trying to add comment in blog everything is fine it shows no error but when i click submit nothing happens i mean it doesn’t add it in data base i dont know what im missing
this is what i have in controller

public function addCommentAction(Request $request, $id)
    {
        $user=$this->getUser();
        if($user==null)
            return $this->redirectToRoute('fos_user_security_login');
        $add_comment = new CommentaireBlog();
        $em = $this->getDoctrine()->getManager();
        $blog = $em->getRepository(Blog::class)->find($id);
        $add_comment->setBlog($blog);
        $add_comment->setUser($user);
        $add_comment->setDate( new DateTime());

        $form = $this->createFormBuilder($add_comment)

            ->add('contenu', TextareaType::class)
            ->getForm();

        if ($request->getMethod() == 'POST') {
            $form->handleRequest($request);

            if ($form->isSubmitted() && $form->isValid()) {
                $add_comment = $form->getData();
                $em = $this->getDoctrine()->getEntityManager();
                $em->persist($add_comment);
                $em->flush();

                return $this->redirect($this->generateUrl('blog_details'));
            }
        }

        return $this->render('blog/details.html.twig', array(
            'form' => $form->createView(),
            'comment' => $add_comment,
            'blog' => $blog,
        ));

    }

this is what i have in blog.yml

comment_new:
    path:     /{id}/details
    defaults: { _controller: "BlogBundle:Blog:addComment" }
    methods:  [GET, POST]

and finally this is the twig page

<div class="comments-form">
                                <h4 class="comments-title">Leave A Reply</h4>

                                    <!-- .row -->
                                    <form action="{{ path('comment_new', { 'id': blog.id }) }}" method="post" >

                                        <textarea id="form_comment" name="form[comment]" required="required" class="form-control comments-textarea" placeholder="Comments*"></textarea>

                                        <input type="submit" class="btn btn-default" />


                                </form>
                            </div>
                        </div>

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *