0

enter image description here have create module all filed work properly but checkbox edit time not checked automatically.

$fieldset->addField('hobbies[]', 'checkboxes', array(
            'label' => Mage::helper('contactform')->__('Checkboxs'),
            'name' => 'hobbies[]',
            'values' => array(
                array('value' => 'read', 'label' => 'read'),
                array('value' => 'write', 'label' => 'write'),
                array('value' => 'games', 'label' => 'games'),
            ),
            'value' => array('read', 'games'),
             'disabled' => array('1'),
        ));
1

Use below code

//$selected = array('read', 'games');
$selected = 'get value here from database format as above';

    $fieldset->addField('hobbies', 'checkboxes', array(
                'label' => Mage::helper('cms')->__('Checkboxs'),
                'name' => 'hobbies[]',
                'values' => array(
                    array('value' => 'read', 'label' => 'read'),
                    array('value' => 'write', 'label' => 'write'),
                    array('value' => 'games', 'label' => 'games'),
                ),
                'checked' => $selected,
            ));
0

Put below code in admin form

$model = Mage::registry('authorize_data');
    $fieldset->addField('hobbies[]', 'checkboxes', array(
                            'label'     => 'hobbies',
                            'name'      => 'hobbies[]',
                            'values' => array(
                                array('value'=>'aaa','label'=>'Checkbox1'),
                                array('value'=>'bbb','label'=>'Checkbox2'),
                                array('value'=>'ccc','label'=>'Checkbox3'),
                            ),
                            'checked' => unserialize($model->getHobbies())
                        ));

and in save action use this code

$postData = $this->getRequest()->getPost();
$postData['hobbies'] = serialize($postData['hobbies']);

store this serialize array in your field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.