Symfony2 Form Component - creating fields without the forms name in the name attribute Symfony2 Form Component - creating fields without the forms name in the name attribute symfony symfony

Symfony2 Form Component - creating fields without the forms name in the name attribute


In Symfony3, override AbstractType::getBlockPrefix in child class to return null.


Instead of the createBuilder function use:

$builder = $app['form.factory']->createNamedBuilder(null, 'form', $data, array('validation_constraint' => $constraint));

First parameter being the form name.

Example by Bernhard Schussek himself at https://stackoverflow.com/a/13474522/520114


If you are not using child forms you can set getName method of your form as empty string:

class FormType extend AbstractType {    // ...    public function getName() {        return '';    }}