3

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?

1

Try this:

/** @var \Zend\Stdlib\ParametersInterface $postParameters */
$postParameters = $this->getRequest()->getPost();
$postParameters->fromArray([]);

Use getQuery method to clean GET parameters.

0

You can try like this,

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

unset($formKey);

than after you can try to set again

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

Hope it helps.

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.