Magento filling in checkboxes in admin edit form

I have a form page where I use

$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 that I cannot figure out how to get them to fill out when editing. Can someone tell me how to do this?

I use the type of checkboxes so that they appear as a list, and not on separate lines in a form. If there is a way to create them as separate fields, but all on the same line, I would like to know how.

+4
source share
4 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 the checkboxes with the values ​​"1" and "5" will be marked. For more information you can check lib / Varien / Data / Form / Element / Checkboxes.php

+8
source

I also added the code or you can follow the link below for more help.
http://pastebin.com/hKMmryE9

 Magento, populating checkboxes fields on an admin edit form $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'), ) )); $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') )); 
0
source

Slightly improved and verified:

 $fieldset->addField('payment_methods', 'checkboxes', array('label' => 'Payment Methods', 'name' => 'payment_methods[]', 'values' => array( array('value'=>'1', 'label'=>'Cash'), array('value'=>'2', 'label'=>'Paypal'), array('value'=>'3', 'label'=>'Authorize.Net'), array('value'=>'4', 'label'=>'Square'), ), 'required' => true, 'checked' => array('1','4'), 'disabled' => array('1'), ////if you want )); 
0
source
 Create $array like below Array ( [0] => Array ( [value] => 1 [label] => Value 1 ) [1] => Array ( [value] => 2 [label] => Value 2 ) [2] => Array ( [value] => 3 [label] => Value 3 ) [3] => Array ( [value] => 4 [label] => Value 4 ) [4] => Array ( [value] => 5 [label] => Value 5 ) ) $fieldset->addField('checkboxes', 'checkboxes', array( 'label' => 'Select Value', 'name' => 'checkboxes[]', 'values' => $array, 'onclick' => "", 'onchange' => "", 'disabled' => false, 'after_element_html' => '', 'tabindex' => 1 )); 
0
source

All Articles