Zend: How to populate data to checkboxes?

Posted by NAVEED on Stack Overflow See other posts from Stack Overflow or by NAVEED
Published on 2010-03-20T05:32:20Z Indexed on 2010/03/20 5:41 UTC
Read the original article Hit count: 445

I am working on zend. I have a form with some checkboxes. I want to get data from database and populate this data to this form. If '1' is stored in table field then tick the check box otherwise leave it alone. In textboxes and dropdowns, data is easily populated but how to check a checkbox in action.

I am creating checkboxes and textboxes elements like this in form.php:

// Person name
$person = $this->CreateElement('text', 'name');
$person->setLabel('Name');
$elements[] = $person;    

// Organization name
$person = $this->CreateElement('text', 'organization');
$person->setLabel('Organization');
$elements[] = $person;       

// isAdmin Checkbox
$isAdmin = $this->CreateElement('checkbox', 'isAdmin');
$isAdmin->setLabel('Admin');
$elements[] = $isAdmin;

$this->addElements($elements);
$this->setElementDecorators(array('ViewHelper'));

// set form decorator (what script will render the form)
$this->setDecorators(array(array('ViewScript' , array('viewScript' => 'organization/accessroles-form.phtml'))));

And populating data like this (for example):

// Prepare data to populate
$data['name'] = 'Naveed';
$data['organization'] = 'ABC';
$data['isAdmin'] = '1';

// Populate editable data
$this->view->form->populate( $data );

It is populating data in textboxes but not checking the checkbox? Any idea that how to check a checkbox from action?

Thanks

© Stack Overflow or respective owner

Related posts about zend-framework

Related posts about populate