3

I am trying to add success message in my controller but messages are showing.

In my controller class, I have extended \Magento\Framework\App\Action\Action class and using below code to add success message:

$this->messageManager->addSuccess(
    __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.')
);
  • Are you redirecting to another page after running that code? – Renon Stewart Mar 4 '16 at 12:02
  • At the end of the execute method, I'm using $this->_redirect('contact/index'); to redirect and it's perfectly working. But messages are not showing. – Shyam Mar 4 '16 at 12:05
  • Does the regular contact form show the message after filling out the form? – Renon Stewart Mar 4 '16 at 12:14
  • Default contact us form is also not showing messages – Shyam Mar 4 '16 at 12:59
  • So the code is not your problem then... Are you using any custom theme or did any customization? – Renon Stewart Mar 4 '16 at 13:34
3

I had a similar issue, but with an error message not showing up when expected after submitting the contact form. The error message was not a surprise (I think it's because of not having email supported on the development server I was using). But, one development site displayed the message, and another didn't.

Finally, I turned the cache on for the site that wasn't showing the message and it worked. I think it may have to do with the ajax request for the message timing out since the page takes so much time to load without the cache enabled.

| improve this answer | |

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