ciurciurek ciurciurek - 10 days ago 7
Twig Question

Symfony 3 don't send the form

I'm creating blog in Symfony 3.1.7 and i have a problem with sending the form. I created comment Entity Class. Then I generated form class by console end edited buildForm method. It looks like:

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('content')
->add('save',ButtonType::class);
}


My controller looks like this

/**
* @Route("/article/{id}", name="show_article")
*/
public function showAction( Post $post, Request $request )
{
$comment = new Comment;
$comment -> setPost($post);
$form = $this->createForm(CommentType::class);
$form->handleRequest($request);

if ($form->isSubmitted() ) {
$em = $this->getDoctrine()->getManager();
$em->persist($comment);
$em->flush();
}
return $this->render('default/show.html.twig',[
'post' => $post,
'form' => $form -> createView()
]);
}


Form is displayed by twig helper
{{form(form)}}
.

And the problem is when i try to send form. I clicked on button
and nothing is happening. It looks like form was never subbmited.

Thanks for your help.

Answer

Use SubmitType like so:

->add('save',SubmitType::class);