0

I have created a module that is accessible in admin. In that module i have created a form in the .phtml(template) file and after validating it through javascript i want to save the values in the database in products table. I have searched a lot but i could not make a call to the script! Please guide me how can i send the call to php script and get the data successfully, what modules, controllers etc i have to create to do that? Here is my module structure that is making ajax call,

code->local->myspace->mymodule->(model,controllers,etc,helper) and i have included template file in adminhtml->default->default->templates.

config.xml:

<?xml version="1.0"?>

<config>
    <modules>
        <Inchoo_CoffeeFreak>
            <version>0.1.0</version>
        </Inchoo_CoffeeFreak>
    </modules> 

    <global>
        <blocks>
            <coffefreakblock1>
                <class>Inchoo_CoffeeFreak_Block</class>
            </coffefreakblock1>  
            <coffefreakblock2>
                <class>Inchoo_CoffeeFreak_Block_EditSpecial</class>
            </coffefreakblock2> 
        </blocks>
        <helpers>
            <coffefreakhelper1>
                <class>Inchoo_CoffeeFreak_Helper</class>
            </coffefreakhelper1>
        </helpers>  
    </global>    






    <admin>
        <routers>

           <samplerouter1>
                <use>admin</use>
                <args>
                    <module>Inchoo_CoffeeFreak_AdminControllersHere</module>
                    <frontName>admin</frontName>

                    <modules>
                        <sintax after="Inchoo_CoffeeFreak_AdminControllersHere">Mage_Adminhtml</sintax>
                    </modules>
                </args>
           </samplerouter1>           
        </routers>      
    </admin>





    <adminhtml>


        <menu>
             <mymenu1 translate="title" module="coffefreakhelper1">
                <title>PrintInfo</title>
                <sort_order>20</sort_order>
                <children>
                <!-- Note the misleading "module" attribute. 
                    It actualy refers to one of the declared helpers -->

                    <myitem1 translate="title" module="coffefreakhelper1">
                        <title>Add configuration</title>
                        <action>samplerouter1/FreakOut</action>
                        <sort_order>1</sort_order>                        
                    </myitem1>

                    <myitem2 translate="title" module="coffefreakhelper1">
                        <title>Change configuration</title>
                        <action>samplerouter1/FreakOut2</action>
                        <sort_order>2</sort_order>                        
                    </myitem2>                    


                </children>
             </mymenu1>
        </menu>
    </adminhtml>  
</config>
12
  • Can you add your code for config.xml Commented Dec 5, 2012 at 14:50
  • you mean code->local->myspace->mymodule->etc->config.xml ???? Commented Dec 5, 2012 at 14:51
  • Are you trying to add or update product? Commented Dec 5, 2012 at 14:57
  • Update. I am updating some attributes when form is being submitted! Commented Dec 5, 2012 at 14:57
  • I am just not able to send the values that i get from the form to the php script so that i can save them in database! Commented Dec 5, 2012 at 14:58

1 Answer 1

2

You should be able to accomplish most of what your trying to do within the product admin, but if your want to create your own custom module to save product data then you would need to do something like this

app/code/local/myspace/mymodule/controllers/IndexController.php

<?php
class Myspace_Mymodule_IndexController extends Mage_Core_Controller_Front_Action
{
    public function SaveAction()
    {
        $product_id = Mage::app()->getRequest()->getParam('product_id')
        $product = Mage::getModel('catalog/product')->load($product_id);
        $product->setName('new_name');
        .....
        $product->save()
    }
}

Take a look @ http://www.phpzag.com/create-custom-module-with-custom-database-table/

In your phtml file, you would need to post your ajax action to www.site.com/admin/mymodule/index/save

Sign up to request clarification or add additional context in comments.

3 Comments

The problem is that i have to get the data from a form. So to get data in php from html i need to submit the form and get data through post or through ajax request! and then i have to update product according to that!
@R.S. answered this part of the question you use this code: $product_id = Mage::app()->getRequest()->getParam('your_param')
In my admin, secure keys are turned on! So i have seen in firebug that it sends the request to dashboard as it doesn't identify the key! So what should i do for that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.