Peter
Peter

Reputation: 9123

How to name a form in symfony2?

I've got the following code to create a form in symfony2.

private function createDeleteForm($id)
{
    return $this->createFormBuilder()
        ->setAction($this->generateUrl('anne_stage_delete', array('id' => $id)))
        ->setMethod('DELETE')
        ->add('delete', 'submit')
        ->getForm()
    ;
}

But I can't find out how to add/change the name attribute. When I look in the rendered html the form name is form.

Upvotes: 0

Views: 62

Answers (1)

Mohamed Ben HEnda
Mohamed Ben HEnda

Reputation: 2776

Make the form name in twig

<form action="{{ path('yourpath') }}" method="post" name="your_name-form">
{{ form_widget(form) }}
</form>

Or

You can use createNamedBuilder

$form = $this->get('form.factory')->createNamedBuilder('your-custom-name', 'form',  null, array(
    'constraints' => $collectionConstraint,
))
->add('delete', 'submit')
->getForm();

Upvotes: 1

Related Questions