3

I have three contact-us forms that are CMS pages. They are on separate websites, and they all have different URL keys. The CMS pages have their own phtml forms but use the same controller action (form_action="/contacts/index/post") for posting as defined in the CMS.

Current behavior:

Each of these forms submit just fine, but, after submission, they are redirected to the /contacts/index/ (through $this->_redirect('*/*/')) and the redirected pages are not what the customer started from, of course.

Desired behavior:

I would like the redirected page to be the same form page that the customer starts from. What's one of the cleanest and make-sense way to do this? Should I create an extension with a controller that basically does what the Mage_Contacts module does, but with a different redirect logic?

5
  • use the method $this->_redirect('*/*/'); in your controller. I think that is the best option. Mar 28, 2014 at 1:03
  • Try using $this->_redirectReferer() instead of $this->_redirect('*/*/')
    – Marius
    Mar 28, 2014 at 8:31
  • @Marius, would you do what I said to produce the desired behavior (i.e. create a controller that does basically the same thing as contacts/index/post with the redirect to the referer`) or approach it differently? I'm just trying to get an idea of how people would approach and solve this kind of issues.
    – laketuna
    Mar 28, 2014 at 13:43
  • @laketuna I would override the default contact controller. inchoo.net/ecommerce/magento/…. And in the postAction method I would call the same code except the redirect part.
    – Marius
    Mar 28, 2014 at 13:48
  • @Marius, OK, that sounds good, and it was what I was thinking would be the best approach. Feel free to create an answer for it!
    – laketuna
    Mar 28, 2014 at 13:55

1 Answer 1

3

As described in the comments....

I would override the default contact controller and in the postAction method I would call the same code except the redirect part.
Instead of calling at the end

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

I would call

$this->_redirectReferer();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.