Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento, populating checkboxes fields on an admin edit form

Tags:

magento

I have a form page where I am using

$form->addField('name', 'checkboxes', array('label' => 'check', 'name' => 'name[]',
    'values' => array(
        array('value'=>'1', 'label'=>'1'),
        array('value'=>'2', 'label'=>'2'),
        array('value'=>'3', 'label'=>'3'),
        array('value'=>'4', 'label'=>'4'),
        array('value'=>'5', 'label'=>'5'),
    )
));

to create a list of checkboxes.

The problem is I can't figure out how to get them to populate when editing. Can anyone tell me how to do this?

I am using the checkboxes type so they display as a list instead of in separate rows in the form. If there is a way to create them as separate fields but all in one row I would love to know how.

like image 337
Ryan Avatar asked Jan 17 '23 11:01

Ryan


1 Answers

$form->addField('name', 'checkboxes', array('label' => 'check', 'name' => 'name[]',
    'values' => array(
        array('value'=>'1', 'label'=>'1'),
        array('value'=>'2', 'label'=>'2'),
        array('value'=>'3', 'label'=>'3'),
        array('value'=>'4', 'label'=>'4'),
        array('value'=>'5', 'label'=>'5'),
    ),
    'value' => array('1', '5'),
    // or 
    // 'checked' => array('1', '5')
));

Then checkboxes with values "1" and "5" will be checked. For more details you can check lib/Varien/Data/Form/Element/Checkboxes.php

like image 162
Sergii Stotskyi Avatar answered Jan 31 '23 06:01

Sergii Stotskyi