Magento Tutorials

Magento 2 “Invalid Form Key. Please refresh the page”

Sometimes when you create a product with multiple attributes in Magento 2, you may end up with the error message “Invalid Form Key. Please refresh the page.

Magento 2 invalid form key please refresh the page
 Magento 2 “Invalid Form Key” error

To get rid of this message, you need to increase the value of max_input_vars in php.ini file. By default, this value is set to 1000. You should set it to 5000 or 10000.

To do that, follow these steps:

1. Log in to your website server using ssh
magento server login

2. Go to the folder containing php.ini and open this file by vi

3. Edit the value of max_input_vars to 5000 (or create it if it doesn’t exist yet). Then, press ESC key and type :wq to save the file.

4. Restart your Mamp or Apache. Now you can save your newly created product without any problem.

See more:
Guide to Enable/Disable or Clear Cache in Magento 2
Magento 2 Error: One or more indexers are invalid
Warning: Your Magento folder does not have sufficient write permissions

Is it helpful?

A knowledge craver who always strive to be wiser everyday.

Notify of
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Hussain Badusha
Hussain Badusha
10 months ago

Thanks for the help.
I tried you method but it didn’t solve the issue for me

Actually i’m newbie in magento 2 development.
I’ve been working on magento 2 module.
So i created a admin menu and everything works good.
But when i click on the created menu, it goes and redirects admin dashboard page and display the error

“Invalid security or form key. Please refresh the page.”

Fyi, i doing this in windows 7 PC and localhost server xampp

Any help would be appreciable.

10 months ago

Hey, I had the same problem, your admin menu action attribute is wrong. So for example, in your app/code/Mageplaza/HelloWorld/etc/adminhtml/menu.xml There is line where you specify your route. You need to change your action=”mageplaza_helloworld/post” It goes like this : action=”{router_name} / {controller_folder} / {action_name}” Your router name is your namespace and module name – in this case it is Mageplaza_HelloWorld Your controller folder is the folder inside app/code/Mageplaza/HelloWorld/Controller/Adminhtml – in your case it may be Post Your action name is the .php file inside app/code/Mageplaza/HelloWorld/Controller/Adminhtml/Post – in your case it may be Index.php TLDR: In your app/code/Mageplaza/HelloWorld/etc/adminhtml/menu.xml On the line that… Read more »

2 years ago

Thank you.You saved my time

1 year ago

Thanks so much – you saved my day!

11 months ago
Reply to  Dom

I changed max_input_vars, again getting same error

Hussain Badusha
Hussain Badusha
10 months ago
Reply to  Mansi

Hi Mansi,
I’m also having the same error.
Did you manage to solve this error?

If so, what have you done to get rid of that issue?

10 months ago

I am facing this in some browser.