在Magento中提交联系人表单后重定向到特定页面
用户在Magento中提交联系人表单后,如何重新定向到特定页面?form.phtml具有在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('*/*/'); 改变 $
<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()代码>
- 并通过编辑
并在messages\u product\u视图中添加行app/design/frontend/base/default/template/contacts/form.phtml
,更新表单phtml以包含错误/成功消息
不要编辑核心文件 根据我的经验,我想在提交联系人页面后更改成功消息
{{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>
$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>