Magento 2 Set $_POST to an empty Array()

by Juliano Vargas   Last Updated July 12, 2019 12:09 PM - source

I can't seem to find a way to set $_POST to an empty array.

I have a form in phtml action to self I can get $_POST values the following ways:

$this->getRequest()->getPostValue('form_key');

$this->getRequest()->getParam('form_key');

The Above will give Array ( [form_key] => FThdknnc_347djcncKey_)

Now I've tried to reset by doing:

$this->getRequest()->setPostValue('form_key');

But it gives me:

Array ([form_key] =>)

That ain't right browser still popping up saying that it will resend data from form: It should return Array () But the form_key key is still in the $_POST Array. one can do in php:

$_POST = Array(); and that would be enough but it doesn't work with magento.

Anyone any idea?



Answers 1


You can use unset, check whether still it come out or not..

$params = $this->getRequest()->getParams();
unset($params['form_key']);    
aravind
aravind
July 12, 2019 11:13 AM

Related Questions


Magento 2 simple form submit

Updated July 10, 2016 08:03 AM

Magento 2 | Get Post Params

Updated July 16, 2018 13:09 PM


Magento 2.2.4 : post data in url

Updated July 12, 2018 11:09 AM