I want to add single check box in my extension like below.

enter image description here

Please check my system.xml

                <general translate="label" module="paygate">
                    <label>General settings</label>
                      <visible_on_frontend translate="label">
                        <label>Visible on Front-End</label>


class Namspace_Mymodule_Block_System_Config_Form_Frontendavail extends Mage_Adminhtml_Block_System_Config_Form_Field  
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
        $html = "
           <input type='checkbox' class='required-entry' name='terms' value='1'>";
        return $html;

After doing this check box is display but nothing is happens. Not saving data in database.


1 Answer 1


Not sure about this but your input name is wrong.
It should be in this format groups[general][fields][terms][value].
That structure is needed in order to read the values properly and store them in the database.

Checkboxes are a bit strange.
If you don't check them, no value is sent via post and the way the system configuration section works for magento it will ignore the not checked field.
You should try as much as possible to avoid checkboxes. Use yes/no selects instead.
But if you really want to use the checkbox, me your _getElementHtml method look like this:

protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    $html = "
       <input type='hidden' name='groups[general][fields][terms][value]' value='0'>
       <input type='checkbox' class='required-entry' name='groups[general][fields][terms][value]' value='1'>";
    return $html;

Adding a hidden input with the same name before the checkbox will ensure that something is sent via post even if you don't check the checkbox. When checking the checkbox, the hidden input value will be ignored.

  • can you please help me in detail ?
    – Krupali
    Commented Nov 7, 2016 at 9:46
  • Take a look at the form fields added without a frontend_model. Any field from the core. And you should see the way that the name attribute looks like. That structure is needed in order to read the values properly and store them in the database.
    – Marius
    Commented Nov 7, 2016 at 9:55
  • thank you :) it works and is saving in database. but if i unchecked check box then there is no effect is come in database. instead of this it saving 1 every time (whether check box is checked or not. )
    – Krupali
    Commented Nov 7, 2016 at 10:05
  • see my edit. Maybe it helps.
    – Marius
    Commented Nov 7, 2016 at 10:09

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.