Site icon MageComp Blog

How to fix “Invalid Form Key. Please refresh the page” error in Magento 2

Hello Magento Folks,

In this tutorial, I am going to provide the solution for the most common error in Magento 2, “Invalid Form Key. Please refresh the page”. 

Everyone might have encountered an Invalid form key error while working with Magento admin. Today I am here to resolve this error in two ways. Before that, first, let’s understand the reasons behind the error.

Actions that cause “Invalid Form Key. Please refresh the page” error in Magento 2

The following actions may be the cause for “Invalid Form Key. Please refresh the page” error:

Reasons for “Invalid Form Key. Please refresh the page” error in Magento 2

There are two main reasons that generate “Invalid Form Key. Please refresh the page” error.

PHP Max_input_vars value is not optimized for Magento 2

PHP Max_input_vars is the maximum number of attributes that your server can use for a function. The default value is 1000 which is not enough for Magento 2. This causes the invalid form key error.

Base URL on Localhost not recognized by Magento 2 system

If you encounter an invalid form key error on localhost, it is probably because you will be using localhost as the base URL for your website instead of 127.0.0.1

How to fix “Invalid Form Key. Please refresh the page” error in Magento 2

There are 2 ways to fix “Invalid Form Key. Please refresh the page” error in Magento 2

Solution 1: Increase max_input_vars value in php.ini file

Go to path – /etc/php/7.3/apache2

Now, open your terminal and run the below command

gedit php.ini

Change max_input_vars to 5000 as shown in the below image.

Please check the updated value by phpinfo file.

Solution 2: Modify your base URL

Run the below command  to get rid of the invalid form key error

php bin/magento setup:store-config:set --base-url="http://127.0.0.1:8080/"

Or else you can follow the below steps,

Final Words:

Try the above solutions to get rid of the “Invalid Form Key. Please refresh the page” error in Magento 2. If the error still persists, you can take the help of our Support Team which will guide you to solve the invalid form key error.

Spread the article amongst your friends to help them resolve the error.

Happy Reading!

Exit mobile version