I commented that I am developing a form in symfony 3.4, the form is rendered correctly and displayed on the screen. The problem happens when clicking on the input submit nothing happens when I should save in the database. The code to save what is entered in the form is:
public function agregar(Request $request)
{
$persona = new Persona();
$formulario = $this->createForm(PersonaType::class,$persona);
// $this->render('base.html.twig',array("persona"=>$formulario->createView()));
$formulario->handleRequest($request);
if($formulario -> isSubmitted() && $formulario->isValid())
{
$persona = $formulario->getData();
$db = $this->getDoctrine()->getManager();
$db->persist($persona);
$db->flush();
return new Response('<html>hola </html>');
}
else
{
return new Response('<html>chau </html>');
}
}
I show it in the following way:
/**
* @Route("/post", name="post_list")
*/
public function mostar()
{
$formulario = $this->createForm(PersonaType::class);
return $this->render('base.html.twig',array("persona"=>$formulario->createView()));
}
In twig
<h2>Formulario con Symfony3</h2>
{{form(persona)}}
{{form_end(persona)}}
Try to associate a route to the add () method but it did not work and I'm honestly lost of how to make it work, I await your answers. Greetings