简体   繁体   English

如何在Magento的admin html中为控制器创建自定义表单操作?

[英]How to create a custom form action to a controller in admin html from Magento?

I have created a form in admin html, but its action not working properly, the action not coming to the controller. 我在admin html中创建了一个表单,但是它的操作不正常,操作没有进入控制器。 My config.xml file shown below 我的config.xml文件如下所示

<adminhtml>
        <menu>
            <customercare module="customercare">
                <title>Calls</title>
                <sort_order>100</sort_order>
                <children>
                    <customercare module="customercare">
                        <title>View Missed Calls</title>
                        <sort_order>0</sort_order>
                        <action>admin_customercare/adminhtml_missedcall</action>
                    </customercare>
                    <customercarecalllog module="customercare">
                        <title>View Call Logs</title>
                        <sort_order>1</sort_order>
                        <action>admin_customercare/adminhtml_calllog</action>
                    </customercarecalllog>                    
                </children>
            </customercare>
            <customer>
                    <children>
                            <customercarevirtualretialerrequest module="customercare">
                                    <title>Manage Virtaul Retailers</title>
                                    <sort_order>10</sort_order>
                                    <action>admin_customercare/adminhtml_virtualretialerrequest</action>
                            </customercarevirtualretialerrequest>
                    </children>
            </customer>

        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <customercare translate="title" module="customercare">
                            <title>Calls</title>
                            <sort_order>1000</sort_order>
                            <children>
                                <customercare translate="title">
                                    <title>View Missed Calls</title>
                                </customercare>
                                <customercare translate="title">
                                    <title>Manage Missed Calls</title>
                                    <sort_order>0</sort_order>
                                </customercare>
                                <customercarecalllog translate="title">
                                    <title>View Call Logs</title>
                                    <sort_order>1</sort_order>
                                </customercarecalllog>

                            </children>
                        </customercare>                        
                    </children>
                    <customer>                                        
                            <children>                            
                                <virtualretialerrequest translate="title" module="customer">
                                    <title>Manage Virtual Retailers</title>
                                    <sort_order>10</sort_order>
                                </virtualretialerrequest>                            
                            </children>                                        
                    </customer>

                </admin>
            </resources>
        </acl>

My Controller file 我的Controller文件

<?php
class Suyati_Customercare_Adminhtml_VirtualretialerrequestController extends Mage_Adminhtml_Controller_Action 
{
    protected function _isAllowed()
    {
        return true;
    }

    public function indexAction()
    {

        $this->loadLayout(); 
        $block = $this->getLayout()->createBlock(
            "Mage_Core_Block_Template",
            "virtual-registration",
            array('template' => 'customercare/virtual_retailer_registration_admin_form.phtml')
        );
        $this->_addContent($block);
        $this->renderLayout();

    }

    public function postAction()
    {
        echo "hello"; die();
    }
}

Phtml Form action file located in this path app/design/adminhtml/default/default/template/customercare/virtual_retailer_registration_admin_form.phtml 位于此路径中的Phtml表单操作文件app / design / adminhtml / default / default / template / customercare / virtual_retailer_registration_admin_form.phtml

<form action="<?php echo Mage::helper("adminhtml")->getUrl("customercare/virtualretialerrequest/post"); ?>" id="retailerForm" method="post">
    <input type="hidden" name="form_key" value="<? echo $this->getFormKey(); ?>" />

When i try to submit my form it is going to dashboard not coming to the controller action file. 当我尝试提交表单时,它将转到仪表板而不是控制器操作文件。 please help me on this. 请帮帮我。 I just need to get the post data in the controller file and need to send an email to the admin. 我只需要在控制器文件中获取发布数据,并需要向管理员发送电子邮件。

i think the problem with form key change 我认为表单密钥更改的问题

<input type="hidden" name="form_key" value="<? echo $this->getFormKey(); ?>" />

to

<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM