【问题标题】:Symfony2 fosUserBundle Change Password prevent nested formSymfony2 fosUserBundle 更改密码防止嵌套表单
【发布时间】:2013-04-24 14:32:41
【问题描述】:

如何防止表单 - 通过 Symfony2 - FosUserBundle 呈现 - 被嵌套? 构建器有两个字段,其中一个是重复字段。看来这将被渲染为嵌套

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('current_password', 'password', array(
        'label' => 'form.current_password',
        'translation_domain' => 'FOSUserBundle',
        'mapped' => false,
        'constraints' => new UserPassword(),
    ));
    $builder->add('new', 'repeated', array(
        'type' => 'password',
        'options' => array('translation_domain' => 'FOSUserBundle'),
        'first_options' => array('label' => 'form.new_password'),
        'second_options' => array('label' => 'form.new_password_confirmation'),
        'invalid_message' => 'fos_user.password.mismatch',
    ));
}

当表单被渲染时,我得到的是: http://pastebin.com/Np2bvgvH

如您所见,重复的表单字段被包裹在另一个“FormRows”-div 中。我希望它们是简单的“FormRow”-div,没有额外的 FormRows。布局并不意味着有两个嵌套的 FormRows

希望你能理解我的问题。

谢谢

【问题讨论】:

    标签: php forms symfony nested fosuserbundle


    【解决方案1】:

    看看http://symfony.com/doc/2.0/reference/forms/types/repeated.html

    Symfony 会考虑这种类型的字段。

    【讨论】:

      【解决方案2】:

      解决办法是重新定义repeated_row 块

      {% block repeated_row %}
      {% spaceless %}
      
          {% for child in form %}
              {{ form_row(child) }}
          {% endfor %}
      
      {% endspaceless %}
      {% endblock repeated_row %}
      

      【讨论】:

        猜你喜欢
        • 2023-03-29
        • 1970-01-01
        • 1970-01-01
        • 2023-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多