简体   繁体   English

Magento联系表格重定向

[英]Magento contact form redirect

I'm working on a new site build and the site has two contact forms which run off the same controller. 我正在开发一个新的网站,该网站有两个联系表单,它们在同一控制器上运行。 At the moment the form on the contact page loads a small message saying 'thanks for your inquiry' etc.. The form on the 'gallery' page, once it's submitted sends the user to the contact page and displays the same message. 目前,联系页面上的表单会加载一条小消息,例如“感谢您的查询”等。一旦提交,“图库”页面上的表单会将用户发送到联系页面并显示相同的消息。

However what I want is to keep the user on the page they are currently on and then display the message. 但是,我要使用户停留在他们当前所在的页面上,然后显示消息。 Exactly what's currently happening on the contact page. 确切地说,联系页面上正在发生什么。

If I change this piece of code: 如果我更改这段代码:

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

in /code/core/Mage/Contacts/controllers/IndexController.php I can get it to re-direct to the homepage etc but I just want it to display the message on the page i'm on. 在/code/core/Mage/Contacts/controllers/IndexController.php中,我可以将其重定向到首页等,但我只希望它在我所在的页面上显示消息。

Here is the code to my form: 这是我表格的代码:

<form action="<?php echo Mage::getUrl(); ?>contacts/index/post/" id="contactForm" method="post">
<input type='hidden' name='formtype' value='Contact Us Page'/>
        <div class="fieldset">
               <ul class="form-list">
                <li class="fields">
                    <div class="field">
<div class="input-box">
<input onfocus="if(this.value == 'Name'){this.value = '';}"  name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>"  class="input-text required-entry" type="text" onblur="if(this.value == ''){this.value='Name';}" value="Name"/>
                        </div>
                    </div>

                     <li>
<div class="input-box">
<input name="company" id="company" onfocus="if(this.value == 'Company'){this.value = '';}" title="<?php echo Mage::helper('contacts')->__('Company') ?>" value="Company" onblur="if(this.value == ''){this.value='Company';}" class="input-text" type="text" />
                    </div>
                </li>
                    <div class="field">
                      <div class="input-box">
<input name="email" id="email" onfocus="if(this.value == 'Email'){this.value = '';}" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="Email" onblur="if(this.value == ''){this.value='Email';}" class="input-text required-entry validate-email" type="text" />
                        </div>
                    </div>
                </li>

                <li class="wide">
                    <!--<label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>-->
                    <div class="input-box">
                        <textarea name="comment" id="comment" onfocus="if(this.value == 'Enquiry details'){this.value = '';}" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" onblur="if(this.value == ''){this.value='Enquiry details';}" cols="5" value="Enquiry details" rows="3">Enquiry details</textarea>
                    </div>
                </li>
            </ul>
        </div>
        <div class="buttons-set">
<input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
            <button class="submit" type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
</div>
</form>




<script type="text/javascript">
//<![CDATA[
    var contactForm = new VarienForm('contactForm', true);
//]]>
</script>

You could try using the referer URL 您可以尝试使用引荐来源网址

in /code/core/Mage/Contacts/controllers/IndexController.php 在/code/core/Mage/Contacts/controllers/IndexController.php中

 if(Mage::helper('core/http')->getHttpReferer(true)){
    $this->_redirectUrl(Mage::helper('core/http')->getHttpReferer(true)); 
 }
 else{
    $this->_redirect('*/*/');
 }

Magento useful functions cheatsheet Magento有用的功能备忘单

Also you should avoid making changes to core, Take a look @ Magento: Overriding Core Files (Blocks, Models, Resources, Controllers) 另外,您应该避免对核心进行更改,@ Magento:覆盖核心文件(块,模型,资源,控制器)

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

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