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

后端 未结 3 2087
别那么骄傲
别那么骄傲 2020-12-05 07:19

I\'m currently trying to use the Symfony2 Form Component though the Silex microframework.

My login form is generated as follows:

$app = $this->app         


        
相关标签:
3条回答
  • 2020-12-05 07:30

    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 '';
        }
    }
    
    0 讨论(0)
  • 2020-12-05 07:33

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

    0 讨论(0)
  • 2020-12-05 07:46

    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

    0 讨论(0)
提交回复
热议问题