简体   繁体   English

一页上有多个Symfony表单

[英]Multiple Symfony forms on one page

is it possible have 3 or more forms on the same page with same class in ez publish 5 ? 是否可能在ez publish 5中的同一类的同一页面上有3个或更多表单?

when i put 3 form like this 当我把这样的3种形式

 {{ form_start(form) }}
 {{ form_widget(form) }}
 {{ form_end(form) }}

 {{ form_start(form) }}
 {{ form_widget(form) }}
 {{ form_end(form) }}


 {{ form_start(form) }}
 {{ form_widget(form) }}
 {{ form_end(form) }}

render only first form not others. 仅呈现第一种形式,而不呈现其他形式。

and the second question , i want use one class for multiple forms in ez publish, is it possible ? 第二个问题,我想在ez publish中将一个类用于多种形式,这可能吗?

any link or suggest would be helpful for me 任何链接或建议对我都会有帮助

You can use form in form. 您可以在表单中使用表单。

Example Form 1: 示例表格1:

class MyRegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('firstname', TextType::class, array(
                'label_attr' => ['style' => 'display:none'],
                'attr' => ['placeholder' => 'form.profile.firstname']
            ));
    }
}

Example Form 2: 示例表格2:

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // Add Self Form
        $builder
            ->add('email', EmailType::class, array(
                'attr' => ['placeholder' => 'form.email'],
                'label_attr' => ['style' => 'display:none'],
                'translation_domain' => 'FOSUserBundle',
            ));

        // Include First Form
        $builder->add('Profile', MyRegistrationType::class, array(
            'mapped' => true,
            'label' => false,
            'required' => true
        ));
    }
}

Using Form in Controller: 在控制器中使用表格:

// Create Form
$form = $this->createForm(RegistrationType::class);

Render Twig: 渲染树枝:

 {{ form_start(form) }}
 {{ form_widget(form) }}
 {{ form_end(form) }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM