1

How do you add a check box in the system configuration & how do you save that check box value in Database?

<terms translate="label">
    <class>terms-conditions</class>
    <frontend_type>checkboxes</frontend_type>
    <validate>required-entry</validate>
    <frontend_model>mymodule/system_config_form_terms</frontend_model>
    <sort_order>15</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>0</show_in_website>
    <show_in_store>0</show_in_store>
</terms>

Terms.php

<?php
/**
 * Adminhtml customer grid block
 *
 * @category   Mage
 * @package    Mage_Adminhtml
 * @author      Magento Core Team <[email protected]>
 */
class NameSpace_Mymodule_Block_System_Config_Form_Terms 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'> Terms and Conditions (<a href='#'>Click Here</a>)";
        return $html;
    }
}
?>
7
  • Where exactly do you want to add a checkbox? What do you have right now? Is it for a custom module's configuration? What did you already tried to do in the system.xml? Please give us more explanation and code examples of what you want and what you already have tried...
    – 7ochem
    Mar 9, 2015 at 9:46
  • I edited Question Please check
    – Magento AJ
    Mar 9, 2015 at 9:56
  • wow only 9 views and someone is already trying to close this?
    – SR_Magento
    Mar 9, 2015 at 10:18
  • sr_magento : What someone already trying to close ?
    – Magento AJ
    Mar 9, 2015 at 10:53
  • uhm, why not just use the default dropdown functionality for yes/no field? these are already all over the system configuration.
    – Jeroen
    Mar 12, 2015 at 16:10

1 Answer 1

1

The following doesn't work. It seems we can't set a value via system.xml for the checkbox.

Magento has two different checkbox types:

  • checkbox
  • checkboxes

I think you want the first, therefore you have to change the type:

<terms translate="label">
    <class>terms-conditions</class>
    <frontend_type>checkbox</frontend_type>
    <validate>required-entry</validate>
    <frontend_model>mymodule/system_config_form_terms</frontend_model>
    <sort_order>15</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>0</show_in_website>
    <show_in_store>0</show_in_store>
</terms>
3

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.