snierrazzo
snierrazzo

Reputation: 35

How to read values from MultiCheckbox in Zend

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!...

Upvotes: 3

Views: 3556

Answers (1)

Viper_Sb
Viper_Sb

Reputation: 1817

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

Upvotes: 4

Related Questions