Magento 1.9 Database – Save Data from System Configuration Custom Module

databasemagento-1.9

I need some urgent information, I want to save data from my custom module in my database. I did some part but i don't know further Process. Please Help Me Guys.

This Is my system.xml file-

<config>
  <sections>
    <earthfedex translate="label">
      <class>separator-top</class>
      <label>Fedex</label>
      <tab>catalog</tab> <!-- the important one -->
      <sort_order>400</sort_order>
      <show_in_default>1</show_in_default>
      <show_in_website>1</show_in_website>
      <show_in_store>1</show_in_store>
      <groups>
                <settings translate="label">
                    <label>General Settings</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>


                    <fields>

                        <active translate="label">
                            <label>Enable Fedex Extension</label>
                            <frontend_type>select</frontend_type>
                            <config_path>fedex/fedex_acc/active</config_path>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <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>
                        </active>
                       </fields>
                    </settings>



                     <fedex_acc translate="label">
                    <label>Fedex Account Details</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>2</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <key translate="label" >
                            <label>Key</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>

                    </key>

                      <pass translate="label">

                            <label>Password</label>
                        <frontend_type>password</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>

                   </pass>

                     </fields>
                 </fedex_acc>
             </groups>
         </earthfedex>
     </sections>
 </config>

I want to store values from 2 fields
1.Fedex Account Password
2.Password

How to do this?
If you want any information please let me know.
Thank You

Best Answer

Add <backend_model> tag in to your field.

Backend Model – a class which allows to operate with configuration data on the different stages (save, load).

It contains three major methods respectively for each event: _afterLoad(), _beforeSave() and _afterSave().

So you can use _afterSave() method.

Eg :

<addresses>
    <label>Blocked Email Addresses</label>
    <backend_model>yourmodule/system_config_backend_yourfile</backend_model>
    <sort_order>2</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>0</show_in_website>
    <show_in_store>0</show_in_store>
</addresses>

Backend Model Class :

<?php

class Namespace_YourModule_Model_System_Config_Backend_Yourfile extends Mage_Core_Model_Config_Data
{
    protected function _afterSave()
    {
        if (is_array($this->getValue())) {
            /* You can perform your logic here */
        }
    }
} 

I have Refer this Link