Question

Magento 1.9

I want to create a new tab in System > Configuration. In this tab, I need a group tab and in this group tab i want a textarea which is connected to a field of my database. If i edit my textarea, it will modify my database field too.

Look at this: https://prnt.sc/orwph1

I don't know how to connect my textarea with my db.. Create a new tab with a new group it's easy but connect it to the db..

Thanks!

Was it helpful?

Solution

Magento provides inbuild option to create custom config fields. Magento take care by itself for storing and retrieving data from database. You can create custom config field as 1. Create a new system.xml in your modules etc folder. 2. Put the content in system.xml as

<config>
    <tabs>
    <!--This will create a new Tab for you-->
        <customtab translate="label" module="helloworld">
            <label>Tab Name</label>
            <sort_order>99999</sort_order>
        </customtab>
    </tabs>    
    <sections>
        <!--This will create a new Section for Tab-->
        <custom_section translate="label" module="helloworld">
            <label>Custom Group - General</label>
            <tab>customtab</tab> <!--See the tab name matches above tab-->
            <frontend_type>text</frontend_type>
            <sort_order>1000</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
        <groups>
        <!--This will create a new Group for Tab-->
                <general translate="label comment" module="ordercron">
                    <label>General Settings</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>
                    <fields>
            <!--This will create a new field in above group-->  
                    <custom_field translate="label">
                        <label>Custom Config Fields</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>                
                    </custom_field>
                    </fields>
                </general>
            </groups>
        </custom_section>
    </sections>   
</config>
  1. Now you can access the stored data anywhere as

Mage::getStoreConfig('custom_section/general/custom_field');

and for accessing store specific information use

Mage::getStoreConfig('custom_section/general/custom_field',$storeId);

For more information please refer https://alanstorm.com/custom_magento_system_configuration/

Hope it finds you helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top