Magento 2 Get Post Data in Observer
Magento 2 Get Post Data in Observer– We can get the form post/get value in observer using request interface in constructor. Here in this tutorial, we are going to explain how you can get the form post data in observer in Magento 2.
Magento 2 Get Post Data in Observer Example
First of all you need to inject \Magento\Framework\App\RequestInterface $request in class constructor then you can get the form post value in observer simply as below-
–
Example:
<?php namespace Test\Helloworld\Observer; use Magento\Framework\Event\ObserverInterface; class MyObserver implements ObserverInterface { public function __construct( \Magento\Framework\App\RequestInterface $request ) { $this->_request = $request; } public function execute(\Magento\Framework\Event\Observer $observer) { $postData = $this->_request->getPost(); print_r($postData); } } |
On the same way you can use request/post or get method to get the form post data.
Advertisements
Add Comment
📖 Read More
- 1. Magento 2 get product collection by category id
- 2. Magento 2 get store id by store code
- 3. Magento 2 get product collection filter by Attribute
- 4. Magneto 2 Add product to cart programmatically
- 5. Magento 2 Override Controller