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.

  • Can you please explain your question in detail? – Ronak Chauhan Nov 14 '16 at 5:57
  • Please check updated question – Nitin Pawar Nov 14 '16 at 5:59
  • still need to add all information in detail with example – Ronak Chauhan Nov 14 '16 at 6:00
  • @RonakChauhan i have updated my question. I hope this will help you. – Nitin Pawar Nov 14 '16 at 6:07
  • I had the same problem and got the answer, you can refer here: enter link description here – user47136 Nov 15 '16 at 9:53
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'
            ]
        );
| improve this answer | |
  • Hi It's working, but when i try to save data from the same field it returns empty string. – Nitin Pawar Nov 15 '16 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'),
                   )
            ]
        );
| improve this answer | |
  • Which value you have used as male and female? I mean 1 for male and 0 for female? – Prashant Valanda Nov 14 '16 at 6:22
  • @NitinPawar check updated answer – Prashant Valanda Nov 14 '16 at 6:28
  • It's giving error undefined variable $isDisabled – Nitin Pawar Nov 14 '16 at 6:44
  • remove disable update answer check it – Prashant Valanda Nov 14 '16 at 6:45
  • @NitinPawar IT'S WORKING OR NOT? – Prashant Valanda Nov 14 '16 at 7:47

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.