php - 如何从 Zend 中的 MultiCheckbox 中读取值

标签 php zend-form-element

我对这个 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/

相关文章:

PHP include/require 内部函数

javascript - CORS 问题 - Angular/PHP/Apache

php - 使用 PHP 的 AJAX 代理,这可能吗?

php - Zend 多复选框 : set maximum selection

zend-framework - Zend EmailAddress Validation 返回多个错误

php - 未定义类常量 'MYSQL_ATTR_INIT_COMMAND' 与 pdo

php - MySQL查询,多列求和

php - Zend Framework 3 - 使用 javascript 添加和删除新的输入元素部分

php - Zend Forms - 元素 ID 修改以允许重复使用

php - Zend Framework notEmpty 验证器 setRequired