Nikul
Nikul

Reputation: 1025

How to set checkbox checked in Zend

I want to check my checkbox at edit time in Zend form. I have code for checkbox

    $master = new Application_Model_DbTable_MasterTables();
    $functionalList = $master->buildSelectListbyTable('mst_functional_areas', 'id', 'functional_area', "enable = '1'");

    $area = new Zend_Form_Element_MultiCheckbox('functional_area');
    $area->addMultiOptions($functionalList)->setLabel('Functional area of Specialization / Interest *:')->setAttrib('class', 'required');

    $this->addElement($area);

Now i have array at edit time

Array
(
    [id] => 9
    [user_id] => 15
    [work_experience] => 12
    [functional_area] => Array
        (
            [0] => 1
            [1] => 2
        )
    [industrial_sector] => a
    [add_date] => 2014-01-27 12:06:03
)

functional_area is the array.So i want to check functional_array's value checked with the checkboxes.

Upvotes: 0

Views: 442

Answers (3)

s7anley
s7anley

Reputation: 2498

Always check source code e.g. – Checkbox.php. You can try setChecked(true).

Upvotes: 0

Ashwin Parmar
Ashwin Parmar

Reputation: 3045

$data = Array
(
    [id] => 9
    [user_id] => 15
    [work_experience] => 12
    [functional_area] => Array
        (
            [0] => 1
            [1] => 2
        )
    [industrial_sector] => a
    [add_date] => 2014-01-27 12:06:03
);

$area->setValue($data["functional_area"]);

You can set values like above.

Upvotes: 3

Volvox
Volvox

Reputation: 1649

You can use setValue() like this $area->setValue($functional_area);

Upvotes: 2

Related Questions