Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento module system.xml checkbox won't save

In Magento v1.5.0.1, does anyone know of an issue using the <frontend_type>checkbox</frontend_type> configuration directive in the system.xml? In even the simplest of dumb modules that only have a single config variable and no blocks/models, if I check the box and hit "Save" it reloads the page with the checkbox deselected, even though it says that the configuration was saved successfully. I searched through the code and it's only used in a couple of places. Most of the time, people use <frontend_type>select</frontend_type> with <source_model>adminhtml/system_config_source_yesno</source_model>. This works, but why doesn't the checkbox work too? Or am I misunderstanding how the Magento checkbox is supposed to work?

If it helps, here are my files. In this case I've added a text field variable as well. If I enter text and hit save, that does save, but the checkbox does not:

config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Brian_Stupid>
            <version>0.1.0</version>
        </Brian_Stupid>
    </modules>
    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <stupid translate="title">
                                            <title>Stupid Crap</title>
                                        </stupid>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

system.xml:

<?xml version="1.0"?>
<config>
    <sections>
        <stupid translate="label">
            <label>Stupid Test</label>
            <tab>catalog</tab>
            <frontend_type>text</frontend_type>
            <sort_order>998</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <debug translate="label">
                    <label>Debugging</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>5</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <debugmode translate="label">
                            <label>Debug Mode Enable</label>
                            <comment>If enabled, does not alter database. Prints debug messages and dies</comment>
                            <frontend_type>checkbox</frontend_type>
                            <sort_order>5</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </debugmode>
                        <texttest translate="label">
                            <label>Text Test</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </texttest>
                    </fields>
                </debug>
            </groups>
        </stupid>
    </sections>
</config>
like image 653
Mageician Avatar asked Aug 26 '11 15:08

Mageician


1 Answers

I post you my solution as I'm facing a similar situation

Basically the problem is that magento save only the input parameter 'value' in db while in the input checkbox the important value is 'Checked'.

I tried to put some js that when the checkbox change set the input value according to this and when the page load does the opposite ... This doesn't work.

alternative solution: use a dropdown

 <debugmode translate="label">
                        <label>Debug Mode Enable</label>
                        <comment>If enabled, does not alter database. Prints debug messages and dies</comment>
                        <frontend_type>select</frontend_type>                                                                     
                        <source_model>adminhtml/system_config_source_yesno</source_model>     
                        <sort_order>10</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </debugmode>
like image 128
WonderLand Avatar answered Oct 30 '22 10:10

WonderLand