Question

I am working in magento 1.9 . I have created a custom tab in admin -> configuration . There I created custom fields , I want to save the data from those custom fields on click "save config" button. Here is my code from system.xml

 <section_two translate="label">
                <label>Carrier</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>
                    <carriers>
                        <frontend_model>LtlFreight/adminhtml_system_config_form_carriers</frontend_model>
                        <sort_order>9</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </carriers>
                </fields>
            </section_two>

This my code from .phtml

 <tbody>
    <?php 

    $counter = 1;
    $storeId  = Mage::app()->getStore()->getStoreId();
    $configValue = Mage::getStoreConfig('LtlFreight/section_two/carriers',$storeId);
    $output_data = array();
    $output_data= json_decode($configValue);

    foreach($output_data as $key=>$config_data){

        foreach($config_data as $k => $data){
            echo "<tr>";
            echo "<td>";
               echo  $counter;
            echo "</td>";
            echo "<td>";
               echo $data->CarrierName;
            echo "</td>";  
            echo "<td>";
               echo '<img src="'.$data->CarrierLogoUrl.'"  height="50" width="70">';
            echo "</td>";
            echo "<td>";
               echo '<input type="checkbox" name="" value="'.$data->CarrierSCAC.'"  class="cerasisQuoteServices" >' ;
            echo "</td>";
            echo "</tr>";
            $counter++;
            }

        }?>
    </tbody>

Here I want to save the values of checkboxes on click "save config" button . Anybody please tell the procedure .

Was it helpful?

Solution

in your config.xml add code as follows:

<controller_action_postdispatch_adminhtml_system_config_save>
    <observers>
       <myobserver>
           <type>singleton</type>
           <class>yourextension/observer</class>
           <method>yourmethod</method> 
       </myobserver>
    </observers>
</controller_action_postdispatch_adminhtml_system_config_save>

and declare the observer as

class Vendor_Extension_observer {
     public function yourmethod(Varien_Event_Observer $observer){

         //To get Request parameters in the Observer, use following code
         Mage::app()->getRequest()->getParams();

         //To get post variable
         Mage::app()->getRequest()->getPost('your-param');
     }
}

OTHER TIPS

It is better to check section name, otherwise, the method will fire not only when you need.

    public function yourmethod(Varien_Event_Observer $observer){
 $section = Mage::app()->getRequest()->getParams();
            if ($section['section'] == 'YOUR_SECTION_NAME') {
    $fieldsData = Mage::app()->getRequest()->getPost(groups)[YOUR_GROUP][fields];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top