0

I have created a simple custom theme which has dependency on Magento/blank

Everything in my theme works good except that whenever I add any error/success messages to the messageManager in my custom module and do a redirect to the custom page displaying a form.

It doesn't display those messages.

What I Did

\Magento\Framework\Message\ManagerInterface $messageManager is injected in the constructor

$this->messageManager->addError('Invalid details provided.'); added this in my controler action's execute method

$this->_redirect('myorders/uploadorder/index'); doing a redirect to the page where the form is displayed

What I have already refereed in stack exchange

Magento 2 : success messages are not showing

How to use messageManager to show an error after redirect

Magento 2: Ensure Message Manager Messages Show Up After a Redirct

bumped to the homepage by Community 16 mins ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • try to set message block element cache false . the problem because of cache – Rama Chandran M Jun 21 '17 at 18:09
  • Did you use Ajax? or just a normal controller? – Khoa TruongDinh Oct 1 '18 at 3:14
0

From what I can see with what your posting it doesn't seem to be an issue with the functional more the theme or 3rd party extension removing the message block or you have a js conflict which is preventing it

In my case it was a 3rd party application causing a it to reset the message cookie check in chome cookies and see if the response is being set and reset if so it's most likely a module which is causing the message to be unset

0
 protected $_messageManager;

public function __construct(        
    \Magento\Framework\Message\ManagerInterface $messageManager, 
  ) {   

           $this->messageManager = $messageManager; 
           return parent::__construct($context);

      }

    public function execute()   {

        if(/* set your condition */)
        {

              $this->messageManager->addSuccessMessage(__('Subscriber succesfully  done'));

        }else{

             $this->messageManager->addErrorMessage(__('Already Subscriber'));
        }

        $resultRedirect = $this->resultRedirectFactory->create();
        $resultRedirect->setPath('/');
        return $resultRedirect;

    }
-1

In your controller execute action:

/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$this->_messageManager->addErrorMessage(__('Some error message.'));

$resultRedirect->setPath('your/module/path');

return $resultRedirect;

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.