How to Display Complex Success and Error Message in Magento 2

Hello Everyone,

In this blog, we will learn about how to Display Complex Success and Error Message in Magento 2.

You can display Success Message on Successfully Account Creation, or display a Warning Message on some violation of rule. 

Without wasting your time, let us guide you straight away. Follow the easy step given below to display Complex Success and Error Message in Magento 2.

STEPS FOR DISPLAY COMPLEX SUCCESS AND ERROR MESSAGE IN MAGENTO 2

Step 1: 

<?php

namespace Vendor\Extension\Controller\Index;

use Magento\Framework\Message\ManagerInterface;

use Magento\Framework\App\Action\Action;

class Submit extends Action

{

    protected $messageManager;

    public function __construct(Context $context, ManagerInterface $messageManager)

    {

        $this->messageManager = $messageManager;

        return parent::__construct($context);

    }

    public function execute()

    {

        $this->messageManager->addSuccess(__("Success"));

        $this->messageManager->addError(__("Error"));

        $this->messageManager->addWarning(__("Warning"));

        $this->messageManager->addNotice(__("Notice"));

    }

}

Final Thoughts:

So this was the easiest way which we have told you in this blog. This is how you can display Complex Success and Error Message in Magento 2. Hope you liked the blog.

So quickly go to the comment box and tell me how you like this blog?

Stay tuned with us on our site to get new updates of Magento.

Thanks for reading and visiting our site.

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Leave a Reply

Your email address will not be published. Required fields are marked *