【发布时间】:2013-05-11 06:27:46
【问题描述】:
我想在每个单选/复选框项下创建一个字段集。
例如
Which animals do you like:
[x] Cats
[Fieldset of cat related questions]
[ ] Dogs
[Fieldset of dog related questions]
...
我可以轻松创建字段集和表单,但是将它们嵌套在每个项目下让我有些头疼。
最终我想到了这样的事情:
$this->add(array(
'type' => 'Zend\Form\Element\Radio',
'name' => 'profile_type',
'options' => array(
'label' => 'Which animals do you like:',
'label_attributes' => array('class'=>'radio inline'),
'value_options' => array(
'1' =>'cats',
'fieldsets' => array(
array(
'name' => 'sender',
'elements' => array(
array(
'name' => 'name',
'options' => array(
'label' => 'Your name',
),
'type' => 'Text'
),
array(
'type' => 'Zend\Form\Element\Email',
'name' => 'email',
'options' => array(
'label' => 'Your email address',
),
),
),
)),
'2'=>'dogs',
'fieldsets' => array(
array(
'name' => 'sender',
'elements' => array(
array(
'name' => 'name',
'options' => array(
'label' => 'Your name',
),
'type' => 'Text'
),
array(
'type' => 'Zend\Form\Element\Email',
'name' => 'email',
'options' => array(
'label' => 'Your email address',
),
),
),
))
),
),
'attributes' => array(
'value' => '1' //set checked to '1'
)
));
【问题讨论】:
-
您是否遇到了与渲染相关的问题,或者您是否在询问在代码库上设置表单本身的最佳实践?
-
嗨 Sam,设置表单本身的最佳实践。
标签: forms checkbox radio-button zend-framework2 fieldset