Hi all!
I'm trying to prepopulate checkbox.
I've DB table:
CREATE TABLE IF NOT EXISTS `user` (
`id` tinyint(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(255) NOT NULL,
`reg_date` datetime DEFAULT NULL,
`last_login` datetime DEFAULT NULL,
`group` tinyint(3) NOT NULL DEFAULT '0',
`superuser` tinyint(1) NOT NULL DEFAULT '0',
`last_ip` varchar(19) NOT NULL DEFAULT '0000.0000.0000.0000',
`active` tinyint(1) NOT NULL DEFAULT '0',
`description` text NOT NULL,
`birth_date` date DEFAULT NULL,
`avatar` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=19 ;
I've Form class:
class Models_Form_RadioForm extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$this->setAction('auth/state');
$enabled = new Zend_Form_Element_Checkbox('enabled');
$enabled->setLabel('Group enabled')
->setDecorators(array(
'Label',
'ViewHelper',
'Errors',
array('p' => 'HtmlTag', array('tag' => 'p'))
));
$this->addElement($enabled);
}
}
I've model which returns data from 'active' record:
class Default_DB_User extends Zend_Db_Table_Abstract
{
protected $_name = 'user';
public function getUserData($userId)
{
return
$this->getAdapter()->query($this->select()->from($this->_name, 'active')
->where('id = ?', $userId))->fetch();
}
}
And finally the main function:
function indexAction()
{
$users = new Default_DB_User();
$this->view->users = $users->fetchAll();
$radioForm = new Models_Form_RadioForm();
$users = $users->getUserData(16);
print_r ($users);
$radioForm->populate(array('enabled' => $users));
$this->view->radioForm = $radioForm;
}
print_r ($users) outputs: stdClass Object ( [active] => 1 )
The CheckBox won't be checked :-(
But $radioForm->populate(array('enabled' => 1)) return checked state
$radioForm->populate(array('enabled' => $users)) won't work...
Any solutions?
Thank you!
--
View this message in context:
http://old.nabble.com/Can%27t-prepopulate-state-of-check-boxes-tp26369870p26369870.html
Sent from the Zend Framework mailing list archive at Nabble.com.