1

I want to change the Success Message in the Contact Page. After someone press the submit button the Success page is like this:

enter image description here

How I can to change the Success Page to display a static block for example or to be something like this:

enter image description here

  • @GosuPrzmak you have read my post? I ask about Contact Success page, what you send me is about Order Success page, this two things are very very different. – Robert Feb 11 at 22:56
  • my bad robert i will take a look tomorrow :) – Gosu Przmak Feb 11 at 23:34
2

I think for your requirement you need to overwrite the Magento_Contact Post controller. By default Magento_Contact module redirects to contact/index after you submit the Contact Form. Follow these steps to overwrite.

Added to your custom module di.xml

<preference for="Magento\Contact\Controller\Index\Post" type="[Name Space]\[Your Module]\Controller\Contact\Post" />

Create the custom controller class

<?php

namespace [Name Space]\[Your Module]\Controller\Contact\Post;

class Post extends \Magento\Contact\Controller\Index\Post

{

public function execute($coreRoute = null)

{

    if (!$this->getRequest()->isPost()) {
        return $this->resultRedirectFactory->create()->setPath('*/*/');
    }
    try {
        $this->sendEmail($this->validatedParams());
        $this->messageManager->addSuccessMessage(
            __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
        );        
    } catch (LocalizedException $e) {
        $this->messageManager->addErrorMessage($e->getMessage());     
    } catch (\Exception $e) {
        $this->logger->critical($e);
        $this->messageManager->addErrorMessage(
            __('An error occurred while processing your form. Please try again later.')
        );      
    }
    return $this->resultRedirectFactory->create()->setPath('<Your Module Frontend Page Path>');

}     
}

"Your Module Frontend Page Path" something like custom-module/success

Refer the class for details.

/vendor/magento/module-contact/Controller/Index/Post.php

By overwriting the execute function you re-direct to the new custom page template.

How to create a Custom Page

Please check here.

Hope this answer is helpful.

| improve this answer | |
  • Hi thank you so much for your answer, I have a request to you, can you add the code how we can do the redirect, because in fact this is my question, to overwrite a module I know but I want to know how I can made that redirect to a new .phtml or static block, thank you in advance – Robert Feb 12 at 7:13
  • @Robert updated please have a look now. – Sudhanshu Bajaj Feb 12 at 7:53
  • thank you very much, can you tell me please how this code redirect the success page to a static block? – Robert Feb 12 at 8:57
  • If you using the default contact form page then this overwrite controller will handle the post form request. At first it will do all the necessary stuff of sending email or any error message. Then last line of the function will redirect to your Custom Page which is loading the static block. @Robert – Sudhanshu Bajaj Feb 13 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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