views:

99

answers:

1

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

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



  ));

Thanks for the support!...

A: 

Retrieve it with getValue()

$type->getValue();

It'll be an array with ONLY the elements that were 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 an array like this (IF both are checked)

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

if say only checkbox 2 was checked the array will be

Array
(
    [0] => 2
)

If no checkboxes were checked the getValue() will return NULL

Viper_Sb