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');
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With