redirect to a particular page after contact form is submitted in Magento

redirect to a particular page after contact form is submitted in Magento

July 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
redirect to a particular page after contact form is submitted in Magento

Redirecting to a Particular Page After Contact Form Submission in Magento

When it comes to handling user interactions like form submissions in Magento, understanding the flow of data is crucial. In this post, we’ll guide you through redirecting to a specific page after your contact form submission.

Understanding the Contact Form Flow in Magento

The contact form in Magento is managed primarily by two key components: the contacts/index/post action and the IndexController.php file located under app/code/core/Mage/Contacts/controllers.

When a user submits the contact form, the data is POSTed to this action. The form submission is handled by the controller to process the email and then redirect the user.

The Contact Form Redirect in IndexController.php

You’ve already found the relevant section of the IndexController.php file where the redirection occurs:

public function postAction()
{
    // Email processing logic here...

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

The _redirect() method is a core Magento method that redirects to a specified URL. The '/*/' syntax means it redirects back to the same page (the contact form page).

Redirecting to a Different Page

To redirect to a different page after submission, you can modify this redirection logic. Let’s say we want to send users to our “Thank You” page located at thankyou.html.

First, ensure your “Thank You” page is accessible via Magento by creating a route or using a static block.

Then, update the postAction() method in IndexController.php:

public function postAction()
{
    // Email processing logic here...

    $this->_redirectUrl(Mage::getBaseUrl().'thankyou.html');
}

Here’s what we’ve done:

  1. We use $_redirectUrl($url) instead of _redirect('*/*/') to set the URL for redirection explicitly.

  2. Mage::getBaseUrl() gets the base URL of your Magento site (e.g., “http://example.com”).

  3. We append our “Thank You” page URL (thankyou.html) to this base URL.

This code will now redirect the user to the “Thank You” page after successfully processing and sending the contact form email.

Conclusion

Redirecting users after a successful form submission is an essential part of providing a seamless user experience. By understanding the flow of data in Magento and leveraging core redirection methods, you can easily customize this behavior.

Remember to test your changes thoroughly, as they involve modifying core files which could impact other functionalities. Always backup before making modifications and consider using child themes or custom modules for development purposes.

For more advanced form handling techniques, check out our guide on Building Custom Contact Forms in Magento at Laravel Company.

Email Pricing

Our network