2013-11-12 18:26
浏览 110


I have a module which had instaled a CMS page with some default URL and some text with form. On this form I have fields and submit. I validate my fields using ajax(send POST in controller of my module). If validation is OK, I redirect to the same page with "succes message".

The problem is, that the default URL of this CMS page in which I make redirect after succes submit can be changed in BO - that's why I cannot just $this->_redirect('default_URL') in my controller, because this url can be changed.

What should I do?

EDIT : Solution: use $this->_redirectReferer() in my controller after success validation

图片转代码服务由CSDN问答提供 功能建议

我有一个模块,其中包含一个带有一些默认URL和一些带有表单的文本的CMS页面。 在这个表格上我有字段并提交。 我使用ajax验证我的字段(在我的模块的控制器中发送POST)。 如果验证没问题,我会使用“succes message”重定向到同一页面。

问题是,在成功提交后我在其中进行重定向的CMS页面的默认URL可以在BO中更改 - 这就是为什么我不能只是 $ this-> 我的控制器中有_redirect('default_URL'),因为这个url可以更改。


编辑:解决方案:在我的控制器中使用$ this-> _redirectReferer() 成功验证后

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dou7851 2013-11-12 19:14

    Try to put "back URL" to your form as a hidden field or you can use $this->_redirectReferer() to redirect back to CMS page.


    If you want to redirect to some certain CMS page (not the one where form is placed) you can do this:

    1. Add dropdown to system configuration to be able to select "Success page" (much better than hardcode cms page ID)

    2. Redirect to this page in your controller


    $pageId = Mage::getStoreConfig('mymodule/config/success_page');
    $page = Mage::getModel('cms/page')->load($pageId);
    解决 无用
    打赏 举报
  • dongsui5464 2013-11-12 18:58

    You can get a store config by using the getStoreConfig method, something like


    See Alan's blog, about detailed instructions how to create custom config values (which you might already have) and to access them.

    解决 无用
    打赏 举报
  • dongwei4103 2014-04-10 17:31

    Use this code for redirect to referer

    <?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());?>

    For example in custom login form:

    <form method="post" action="<?php echo Mage::helper('customer')->getLoginPostUrl() ?>">
        <?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());?>
    解决 无用
    打赏 举报

相关推荐 更多相似问题