我对这个 Zend 表单元素有疑问,如何读取 Multicheckbox 的元素状态?
$type= new Zend_Form_Element_MultiCheckbox('typer');
$type->setLabel('Type');
$type->addMultiOptions(array(
'1' => 'type1',
'2' => 'type2'
));
感谢支持!...
最佳答案
使用 getValue() 获取它
$type->getValue();
它将是一个仅包含已检查元素的数组。
即
<input type="checkbox" name="type[]" id="campaign_id" value="1" />
<input type="checkbox" name="type[]" id="campaign_id" value="2" />
将返回一个这样的数组(如果两者都被选中)
Array
(
[0] => 1
[1] => 2
)
如果说只有复选框 2 被选中,数组将是
Array
(
[0] => 2
)
如果没有复选框被选中,getValue() 将返回 NULL
关于php - 如何从 Zend 中的 MultiCheckbox 中读取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3343819/