Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Magento中提交联系人表单后重定向到特定页面_Magento - Fatal编程技术网

在Magento中提交联系人表单后重定向到特定页面

在Magento中提交联系人表单后重定向到特定页面,magento,Magento,用户在Magento中提交联系人表单后,如何重新定向到特定页面?form.phtml具有 <form action="<?php echo Mage::getUrl(); ?>contacts/index/post/" id="contactForm" method="post"> app>code>core>Mage>Contacts>controllers下的IndexController.php $this->_redirect('*/*/'); 改变 $

用户在Magento中提交联系人表单后,如何重新定向到特定页面?form.phtml具有

<form action="<?php echo Mage::getUrl(); ?>contacts/index/post/" id="contactForm" method="post">

app>code>core>Mage>Contacts>controllers下的IndexController.php

$this->_redirect('*/*/');
改变

$this->_redirect('*/*/');


现在它会重新指向主页。

我知道它的答案,只是分享我的经验。 我通过CMS页面制作了一份联系表。这个表格很好用。但在提交后,它将重定向到magento联系人表单。要将其重定向回CMS页面,我必须

$this->_redirect('contactus');
其中
contactus
是URL标识符

同样在重定向之后,成功/错误消息也不会显示。为此,我不得不在这里做出改变

去 /app/design/frontend/default/yourstore/template/contacts/form.phtml


与:



我从

中得到了解决方案,也可以创建自定义url重定向

  • id路径-联系人/索引
  • 请求路径-联系人/索引
  • 目标路径-“重定向url”

为了避免覆盖核心文件并损害更新兼容性,我按如下所述重载了控制器:



显示错误消息。

组合解决方案在@Simon和其他人的回答中给出

  • app/code/core/Mage/Contacts/controllers/IndexController.php中的
    $this->\u重定向('*/*/')
    更改为
    $this->\u redirectReferer()
  • 并通过编辑
    app/design/frontend/base/default/template/contacts/form.phtml
    并在messages\u product\u视图中添加行
    ,更新表单phtml以包含错误/成功消息
最好将文件复制到“本地”以便下一个人使用

  • 转到silk软件并使用模块创建者创建新模块
  • 输入您的公司名称和模块名称
  • 然后将“需要重写Magento类”更改为“是”
  • 单击“添加类”,类名将为Mage\u Contacts\u IndexController
  • 这将创建一个包含您需要的所有内容的模块
  • 将核心控制器中的postAction方法添加到新创建的控制器中
  • 然后在postAction方法的末尾将重定向更改为redirectReferer()
  • 模块创建者将创建您所需的一切,以使联系人控制器过载,并为您节省排错时间。此外,还可以省去直接编辑核心文件的麻烦


    不要编辑核心文件

    根据我的经验,我想在提交联系人页面后更改成功消息

  • 我在静态页面中使用了下面的代码

    {{block type='core/template' name='contactForm' form_action='mywebsiteurl/contacts/index/post' template='contacts/form.phtml'}}
    
  • 我覆盖自定义模块config.xml文件中的默认控制器操作

            <routers>
                <airhotels>
                    <args>
                        <modules>
                            <apptha_airhotels before="Mage_Contacts">Apptha_Airhotels</apptha_airhotels>
                        </modules>
                    </args>
                </airhotels>
            </routers>
    
  • 此表单url定义为:
    $formUrl=basename($this->getRefererUrl())

    提交表单后,将
    /contact/index
    重定向到
    /contact
    是一种非常肮脏但简单的方法

    假设您在模板中扩展Magento联系人,如下所示:

    添加带有以下内容的文件
    Magento\u Contact/templates/form submitted.phtml

    <?php
    header('Location: /contact');
    exit;
    
    一切正常,包括闪光信息


    @noobcode你把行
    $this->\u redirect('contactus')放在哪里了?谢谢。@shnozolla Mage_Contacts_IndexController::postaction如果有人想知道,您可以使用以下代码获取当前CMS页面的URL标识符:
    $cmsPageUrlKey=Mage::getSingleton('CMS/page')->getIdentifier()
    此解决方案建议修改
    core
    中的
    Mage\u Contacts\u IndexController
    。这将导致代码库升级不安全。相反,创建一个自定义模块,并在其中覆盖IndexController。见下面西蒙的答案。这样,您将只负责
    postAction
    而不是整个控制器文件,并且在升级时,您只需将
    postAction
    与升级版本(而不是整个控制器文件)进行比较。对于查看此文件的用户,请不要更改核心!不要编辑此文件。错误做法。不要更改核心文件。那么你建议我们怎么做?我在CMS页面中使用“联系我们”作为块。将文件复制到
    本地
    比直接在
    核心
    中编辑要好,但这仍然不是最佳做法,即在自定义模块中重写控制器文件,并在其中进行更改。这样,当需要升级时,您只需将
    postAction
    与升级版本进行比较,而不必将整个控制器文件进行比较。
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <My_Module_Contacts before="Mage_Contacts">My_Module_Contacts</My_Module_Contacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
    
    <div id="messages_product_view">
      <?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
    </div>
    
    <div id="messages_product_view">
      <?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
      <?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
    </div>
    
    {{block type='core/template' name='contactForm' form_action='mywebsiteurl/contacts/index/post' template='contacts/form.phtml'}}
    
            <routers>
                <airhotels>
                    <args>
                        <modules>
                            <apptha_airhotels before="Mage_Contacts">Apptha_Airhotels</apptha_airhotels>
                        </modules>
                    </args>
                </airhotels>
            </routers>
    
    Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
    $this->_redirect($formUrl); 
    
    <?php
    header('Location: /contact');
    exit;
    
    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <head>
            <title>Contact</title>
        </head>
        <body>
            <referenceContainer name="content">
                <block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form-submitted.phtml">
                    <container name="form.additional.info" label="Form Additional Info"/>
                </block>
            </referenceContainer>
        </body>
    </page>