【发布时间】:2013-07-18 08:47:08
【问题描述】:
我的表单有 3 个集合字段:
$builder->add('affiliates', 'collection', array(
'type' => new AffiliateForm(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'options' => array(
'affiliate_types' => $options['affiliate_types'],
'business_types' => $options['business_types'],
),
));
$builder->add('other_businesses', 'collection', array(
'type' => new OtherBusinessForm(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
));
$builder->add('welfare_activities', 'collection', array(
'type' => new WelfareActivityForm(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'options' => array(
'welfare_activity_types' => $options['welfare_activity_types'],
),
));
在模板中,我将每个子表单字段一一单独显示,如下所示:
<td class="t1c5" >{{ form_widget(affiliate.location) }}
{{ form_errors(affiliate.location) }}</td>
在表格的最后:
{{ form_rest(form) }}
但是当给定集合为空时,它会导致在表格末尾显示以下单词:“附属公司”、“其他企业”、“福利活动”。 所以问题是:
- 为什么这些词会显示在表单上?
-
我可以采取以下措施来避免上述问题:
<div style="display:none;">{{ form_rest(form) }}</div>这是处理问题的正确方法(也许我可以隐藏一个字段或其他什么)?
谢谢。
【问题讨论】:
标签: forms symfony collections