0

I want to add the radio boxes in magento admin panel. Which will also show the selected radio box as per the value stored in the database.

I have the column in database which stores the values from the front end form like Male and Female.

Now i want to add the radio box in admin panel, which will show the radio option selected Male or Female. Based on value stored in database.

6
  • Can you please explain your question in detail? Commented Nov 14, 2016 at 5:57
  • Please check updated question Commented Nov 14, 2016 at 5:59
  • still need to add all information in detail with example Commented Nov 14, 2016 at 6:00
  • @RonakChauhan i have updated my question. I hope this will help you. Commented Nov 14, 2016 at 6:07
  • I had the same problem and got the answer, you can refer here: enter link description here
    – user47136
    Commented Nov 15, 2016 at 9:53

2 Answers 2

0

You can use the 'value' => 'your value/ value from database' attribute after the values attribute array. like

$fieldset->addField(
            'test', //your database field value instead of test
            'radios',
            [
                'label' => __('test'),
                'title' => __('test'),
                'name' => 'test',
                'required' => true,
                'values' => array(
                        array('value'=>'male','label'=>'Male'),
                        array('value'=>'female','label'=>'Female'),
                   ),
                'value' => 'value_from_func'
            ]
        );
1
  • Hi It's working, but when i try to save data from the same field it returns empty string. Commented Nov 15, 2016 at 11:24
0

Add below code in form file

$fieldset->addField(
            'test', //your database field value instead of test
            'radios',
            [
                'label' => __('test'),
                'title' => __('test'),
                'name' => 'test',
                'required' => true,
                'values' => array(
                        array('value'=>'male','label'=>'Male'),
                        array('value'=>'female','label'=>'Female'),
                   )
            ]
        );
8
  • Which value you have used as male and female? I mean 1 for male and 0 for female? Commented Nov 14, 2016 at 6:22
  • @NitinPawar check updated answer Commented Nov 14, 2016 at 6:28
  • It's giving error undefined variable $isDisabled Commented Nov 14, 2016 at 6:44
  • remove disable update answer check it Commented Nov 14, 2016 at 6:45
  • @NitinPawar IT'S WORKING OR NOT? Commented Nov 14, 2016 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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