在zend 2表单的checkbox元素中设置默认的'SELECTED'

时间:2015-12-16 14:17:20

标签: checkbox zend-framework2 zend-form

我想为zend 2中的复选框设置默认'选中'

我尝试添加默认

  

'值'=> '选择'

但它似乎不起作用。

$this->add(array(
            'type' => 'Zend\Form\Element\Checkbox',
            'name' => 'receiveNewsletters',
            'options' => array(
                'value_options' => array(
                    '1' => 'Untick if you do not want to receive promotional emails',
                ),
                'attributes' => array(
                    'value'=>'selected',
                ),
            ),    

        ));

1 个答案:

答案 0 :(得分:0)

该值应为checked_value。默认情况下为'1'

$this->add(array(
    'type' => 'Zend\Form\Element\Checkbox',
    'name' => 'receiveNewsletters',
    'options' => array(
        'label' => 'Untick if you do not want to receive promotional emails',
    ),
    'attributes' => array(
        'value' => '1',
    ),
));