I have a List of entries coming from a database. I would like to have a "Delete-Button" at the end of every row, so that the user won't have to first go to the edit/show page to delete the entry.
I tried creating a hidden input field with the csrf token like so:
return $this->createFormBuilder()
->getForm()
;
this will output:
<div id="form">
<input type="hidden" id="form__token" name="form[_token]" value="6c98ebfa9df07.....">
</div>
The rest of the Form i put around in the twig template so that every form has its own action path according the the id of the entry.
unfortunately in the twig template only the first
{{ form_widget(delete_form) }}
will get rendered.
How can i use this hidden field more often? OR is there any way to do this whole thing differently?
Thanks for any help
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$deleteForm = $this->createDeleteForms();
$entities = $em->getRepository('IntranetServicesBundle:Laender')->findAll();
return $this->render('IntranetServicesBundle:Laender:index.html.twig', array(
'entities' => $entities,
'delete_form' => $deleteForm->createView(),
));
}
private function createDeleteForms()
{
return $this->createFormBuilder()
->add('id', 'hidden')
->getForm()
;
}