2

I have a custom module, it has two fields, table_name and table_number and I have added new field like is_reserve to check if table is reserved,

I have added column in table with integer data type, now I need to add a checkbox for this field on admin form:

$fieldset->addField(
                 'is_reserved',
                 'checkbox',
                 array(
                     'name' => 'is_reserved',
                     'label' => __('is reserved'),
                     'title' => __('is reserved'),
                     'onclick'   => 'this.value = this.checked ? 1 : 0;',
                     /*'required' => true,*/
                 )
             );

I have added this in block file, what else I need to do to get my checkbox working? It will be a great help if someone can give any hint about this.

Thanks

1
  • Can you post your answer?
    – Nitesh
    Apr 27, 2017 at 5:23

1 Answer 1

3

Take a look: vendor/magento/module-customer/Block/Adminhtml/Edit/Tab/Newsletter.php:

$fieldset->addField(
            'subscription',
            'checkbox',
            [
                'label' => __('Subscribed to Newsletter'),
                'name' => 'subscription',
                'data-form-part' => $this->getData('target_form'),
                'onchange' => 'this.value = this.checked;'
            ]
        );

We can follow the same logic.

8
  • Hey, thanks for your quick reply, I have added like this, checkbox appeared, but it does not save the value in field. any hint?
    – Anand
    Dec 28, 2016 at 16:14
  • Try to get the param in your controller? for example: $this->getRequest()->getParams(). Need to check the value is in the params. Dec 28, 2016 at 16:16
  • nope, I am not able to get values of that field in controller.
    – Anand
    Dec 28, 2016 at 16:23
  • All fields are not in the controller? Dec 28, 2016 at 16:25
  • I cant understand, i am new to magento, can you please explain?
    – Anand
    Dec 28, 2016 at 16:25

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.