How to read values ​​from MultiCheckbox in Zend

I have a problem with this Zend form element, how can I read the status of Multicheckbox elements?

    $type= new Zend_Form_Element_MultiCheckbox('typer');
    $type->setLabel('Type');
    $type->addMultiOptions(array(
                        '1' => 'type1',
                        '2' => 'type2'



  ));

Thanks for the support!...

+3
source share
1 answer

Get it using getValue ()

$type->getValue();

This will be an array with ONLY elements that have been checked.

i.e

<input type="checkbox" name="type[]" id="campaign_id" value="1" />
<input type="checkbox" name="type[]" id="campaign_id" value="2" />

will return such an array (if both checkboxes are checked)

Array
(
    [0] => 1
    [1] => 2
)

if it is indicated that only flag 2 has been checked, the array will be

Array
(
    [0] => 2
)

If unchecked, getValue () will return NULL

+4
source

Source: https://habr.com/ru/post/1756745/


All Articles