🔥 Just Launched! Werra Premium Template for HyväSee it in Action

A Simple Solution to Get Postback Data in Controller or Model in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 1 min read

Marketers implement various tactics to gather customer data and use it in employing their strategies to effectively boost businesses and gain conversions.

This data is collected from the customers by asking them to fill out forms and opt for surveys.

Also, developers can use the data filled in the forms to improve the features. For example, the data in the login form or contact form can be used to create an account or manage delivery, etc.

In order to do so, you need to get postback data in controller or model in Magento 2 store.

Here’s the solution to get post data after submission of a form in Magento 2:

Method to get postback data in controller or model in Magento 2:

<?php

namespace Vendor\Extension\Controller\Index;
class Products extends \Magento\Framework\App\Action\Action
{
    public function __construct(\Magento\Framework\App\Action\Context $context)
    {
        return parent::__construct($context);
    }

    public function execute()
    {
        $post = $this->getRequest()->getPost();
        if ($post) {
                //Your Code To perform Action On Post Data
                //To Display Data
                //To Insert Data In Database
        }
    }
}

That’s it.

Do share the post with fellow developers via social media.

Thanks.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.