Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the name of a form without a class?

Tags:

symfony

Here is written how to set the name of a form with a class:

http://symfony.com/doc/2.0/book/forms.html#creating-form-classes

but how to set the name of this form?

$form = $this->createFormBuilder($defaultData)
    ->add('name', 'text')
    ->add('email', 'email')
    ->getForm();

Well, I'm trying to get post parameters after submitting it this way:

$postData = $request->request->get('form_name');
like image 382
ziiweb Avatar asked Oct 17 '11 15:10

ziiweb


1 Answers

I would like to bring some more precision. At least, for the most recent version of Symfony (2.1), the correct symtax (documented on the API) is:

<?php

     public FormBuilderInterface createNamedBuilder(string $name, string|FormTypeInterface $type = 'form', mixed $data = null, array $options = array(), FormBuilderInterface $parent = null)

It is important because you can still pass options to the FormBuilder. For a more concrete example:

<?php

 $form = $this->get('form.factory')->createNamedBuilder('user', 'form',  null, array(
    'constraints' => $collectionConstraint,
))
->add('name', 'text')
->add('email', 'email')
->getForm();
like image 173
tobalsan Avatar answered Oct 20 '22 11:10

tobalsan