cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.3 compatibility evaluation

SOLVED

Magento 2.3 compatibility evaluation

Dear all,

When we faced the error  "Invalid Form Key. Please refresh the page" on submit page"

Preconditions: 
I am using Apache 2.4.6, PHP 7.1.27, and Magento 2.3 on CentOS 7.

Steps to reproduce: 
When I send a "POST" request from the view page to the controller by submitting page then I am getting the Invalid Form Key error. 
"Invalid Form Key. Please refresh the page." 
The error only occurs on Magento 2.3.0. In the earlier version, there was no this. I'm suspecting there is a change in the Magento 2.3.0

Would you please help me?

The detail error as attaches image. 

On Country Setting page, I select the country to be Poland and click Continue to submit page then I am getting the Invalid Form Key error.

 form_key_error.png

One more think there's sometime we got this when calling api and it response as NULL(read on log file).

Is this how Magento handle when the api request time-out or network error?

error2.png

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento 2.3 compatibility evaluation

hello @tarek_elshayal 

 

yes in magento2.3  Form Key is required for all forms at magento backend and frontend as well.
for adding Form Key you need to add below code in your block

protected $formKey;

public function __construct(
    ...    \Magento\Framework\Data\Form\FormKey $formKey
    ...
) {    $this->formKey = $forKey}

public function getFormKey()
{
     return $this->formKey->getFormKey();
}

 and add this code in your phtml file inside form

<input name="form_key" type="hidden" value="<?php echo $block->getFormKey();?>">

If my answer is useful click Kudos and Accept as Solution

View solution in original post

3 REPLIES 3

Re: Magento 2.3 compatibility evaluation

hello @tarek_elshayal 

 

yes in magento2.3  Form Key is required for all forms at magento backend and frontend as well.
for adding Form Key you need to add below code in your block

protected $formKey;

public function __construct(
    ...    \Magento\Framework\Data\Form\FormKey $formKey
    ...
) {    $this->formKey = $forKey}

public function getFormKey()
{
     return $this->formKey->getFormKey();
}

 and add this code in your phtml file inside form

<input name="form_key" type="hidden" value="<?php echo $block->getFormKey();?>">

If my answer is useful click Kudos and Accept as Solution

Re: Magento 2.3 compatibility evaluation

Thank you for your information, i will try it. How about the issue related with api return as NULL? Can you confirm that's how magento handle the time-out request?

Re: Magento 2.3 compatibility evaluation

Can anyone tell me is it a bug of magento when calling api and it response as NULL(read on log file) and show the error like this?error2.png