Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top