【问题标题】:Magento contact form redirectMagento 联系表格重定向
【发布时间】:2019-08-17 05:23:36
【问题描述】:

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

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

如果我更改这段代码:

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

【问题讨论】:

    标签: php javascript forms magento


    【解决方案1】:

    您可以尝试使用引荐来源网址

    在 /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)

    【讨论】:

    • 感谢您的回复,我已尝试添加上述代码。当我提交给我一个空白页面的表单时,我现在只是被指向 /contacts/index/post/。
    • 上述代码前的print_r(Mage::helper('core/http')-&gt;getHttpReferer(true)); die();显示什么?
    • 我似乎无法打印出来,但是如果我添加上面您编辑过的代码,我在提交表单后会得到相同的 URL:www.website.com /联系人/索引/帖子/
    • 它几乎可以工作了,因为我得到了 404 模板渲染,显示了提交表单时显示的代码。它现在给我的网址是'website.co.uk/http:/index/website.co.uk/our-story/gallery'
    猜你喜欢
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2014-04-17
    • 2017-09-28
    • 2012-07-22
    • 2012-10-04
    • 1970-01-01
    • 2015-05-26
    相关资源
    最近更新 更多