0

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 .

  • data on system > configuration page is saved automatically on save. – Shashank Kumrawat Oct 23 '18 at 14:23
  • can you post your all files here with full code ? – Shashank Kumrawat Oct 23 '18 at 21:09
2

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');
     }
}
  • Hi! Thank you for your help , could you please tell me where should i place your code in config.xml? should i place it in event tag or in default tag ? – Mohammad Hamdan Oct 23 '18 at 14:36
  • can you please tell me how to get the post data of config data (actually i only want to get the selected values from checkboxes in post) – Mohammad Hamdan Oct 23 '18 at 15:36
  • 1
    you need to add code into <events> into config.xml. – Dhiren Vasoya Oct 24 '18 at 4:01
  • 1
    I update answer with, how we can get params or post value. you can check it. And if answer help, mark as solution so it will help other in community as well. – Dhiren Vasoya Oct 24 '18 at 4:04
  • thank you for your help , but i want to get the values of selected checkboxes from custom config data . but Mage::app()->getRequest()->getParams(); did show that data . thank you in advance . – Mohammad Hamdan Oct 24 '18 at 5:42
0

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];
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.