php - Magento 联系表单重定向

标签 php javascript forms magento

我正在构建一个新网站,该网站有两个联系表单,它们运行在同一个 Controller 上。目前,联系页面上的表单会加载一条小消息,内容为“感谢您的查询”等。“图库”页面上的表单一旦提交,就会将用户发送到联系页面并显示相同的消息。

但是我想要的是让用户留在他们当前所在的页面上,然后显示消息。联系页面上当前发生的确切情况。

如果我更改这段代码:

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

在/code/core/Mage/Contacts/controllers/IndexController.php 中,我可以让它重定向到主页等,但我只想让它在我所在的页面上显示消息。

这是我的表单代码:

<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>

最佳答案

您可以尝试使用引用 URL

在/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: Overriding Core Files (Blocks, Models, Resources, Controllers)

关于php - Magento 联系表单重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15907359/

相关文章:

javascript - 试图理解这个函数 : Array. prototype.reverse = function() {

Javascript:当 o1 有值并且等于 b1 时,为什么 b1 被视为未定义

sql - 基于表单域的查询条件

php - 如何在 CI 中使用 OR 和 AND 运算符进行查询?

php - PHP 中内置了哪些异常子类?

php - PHP PDO 语句可以接受表名或列名作为参数吗?

ruby-on-rails - 选择所有复选框

javascript - AJAX 发送错误信息

Javascript 闭包 - 变量的生命周期

php form update mysql database 编辑一条记录后返回所有数据库记录