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.

Answers


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


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


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


Need Your Help

How to allow users to check for the latest app version from inside the app?

java android http versioning

I want to add a "Check for update" button in apps so that when someone clicks it, it will display a toast message / progress dialog for checking the app's version.

Linking Me To Wrong Page?

xampp localhost

When I type in localhost/index.php into my URL bar it redirects me to this URL: localhost/xampp/. Why is this happening and why is the localhost/index.php link not taking me to the index.php page?