2

I have a custom form with an action that calls my module controller, I would like to prevent the redirect and stay on the page where the form is submitted but when I try to add a wildcard in my controller index action I get a 'too many redirects error'

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

I've also tried

$this->_redirectReferer();

And

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

Here is my index Action in my module controller

public function indexAction()
{
    $params = Mage::app()->getRequest()->getPost();

    if (isset($params['country'])) {
        $this->setCountry((string)$params['country'], isset($params['hide']));
    }

    if (isset($params['currency'])) {
        $this->setCurrency((string)$params['currency']);
    }
    $this->_redirectReferer();
}

And below is my form which posts to my controller

<form method="post" action="<?php echo Mage::getUrl('locale/switch'); ?>">
    ....
</form>

Is there a better way to have this form submit without redirecting to the controller.

1 Answer 1

3

The answer doesn't involve forcing Magento to stay on the page since

$this->_redirectReferer()

Handles this behaviour nicely for us. The problem itself was due to some pages having a secure URL which meant that Magento would redirect when the form was submitted over https the solution was to change:

<?php echo Mage::getUrl('locale/switch'); ?>

To

<?php echo Mage::getUrl('locale/switch',array('_secure'=>true)); ?>

Now the form can be submitted over secure and unsecure URLs without redirecting

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.