我是ZF2的新手,我有一个很奇怪的问题。我使用数组创建了一个简单的复选框,并将选中的值设置为好,将未选中的值设置为坏。但是当我提交表单时,URL显示选中复选框时,它会发送.....checkbox=bad&checkbox=good...我不知道为什么。
class SearchForm extends Form {
public function __construct($name = null){
parent:: __construct('Search');
$this->setAttribute('method', 'get');
$this->setAttribute ( 'enctype', 'multipart/formdata' );
$this->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'checkbox',
'options' => array(
'label' => 'A checkbox',
'checked_value' => 'good',
'unchecked_value' => 'bad',
),
));发布于 2014-11-26 21:47:02
因为在默认情况下,Zend\Form\Element\Checkbox的use_hidden_element是true。
如果设置为true (默认值),视图帮助器将生成包含未选中值的隐藏元素。因此,在使用自定义未选中值时,此选项必须设置为true。
您可以使用GET方法。当然,您可以在查询字符串中看到两个值: checkbox和hidden元素。
请更仔细地查看ZF2#Checkbox。
发布于 2014-11-26 21:46:54
不是100%确定这是问题的答案,现在不能测试,但它可能与复选框使用try的隐藏元素有关:
$form->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'checkbox',
'options' => array(
'label' => 'A checkbox',
'use_hidden_element' => false,
'checked_value' => 'good',
'unchecked_value' => 'bad'
),
));https://stackoverflow.com/questions/27150131
复制相似问题