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.“

Here are ways you can solve this issue:
Solution 1: Increasing max_input_vars
in php.ini
By default, the value of max_input_vars
in php.ini
is set to 1000. You’ll want to set this to 10000. To edit your php.ini
file, follow these steps:
- Log in to your website server using ssh:

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

3. Edit the value of max_input_vars
to 10000
(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.
Solution 2: Changing your base URL
Another possible reason for this issue is because your base URL is not recognized by the Magento 2 system. This is most commonly seen in local environments (localhost). To get around this, run this command to change your base URL to “127.0.0.1”:
php bin/magento setup:store-config:set --base-url="http://127.0.0.1:8080/"
Or go to your PHPAdmin and find the following table: core_config_data, and change the value of web/unsecure/base_url to 127.0.0.1:

After changing your base URL, flush your cache to apply changes:
sudo rm -rf var/cache var/generation var/page_cache
To learn more knowledge about Magento 1 & 2, you can read our other helpful tutorials.
Recommending Reading:
Guide to Enable/Disable or Clear Cache in Magento 2
Magento 2 Error: One or more indexers are invalid
Hi,
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
Fyi, i doing this in windows 7 PC and localhost server xampp
Any help would be appreciable.
Thanks,
Hussain.
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 »
thanks for the help but it dosent work.
I have Magento 2.4.1, max_input_vars is 20000 but still having the invalid key issue for only one product attribute(Dropdown with 13 options), when I save it without change, or update its values. I can edit this particular attribute only…
I made a very similar attribute with a new name and it gets saved without any issue, but why not this original one!
please guide.
Security breaches, performance issues, scalability issues, lack of features and functionality, etc. are the critical issues in Magento. You must fix these issues before it harms your business. https://www.alakmalak.com/?UTM-andrew-aug/ has helped me multiple times to get through this issue efficiently.
Thank you.You saved my time
You’re welcome!
Thanks so much – you saved my day!
Glad it helps!
I changed max_input_vars, again getting same error
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?
Thanks.
You able to resolve this issue?
Hi,
I am facing this in some browser.
yes, i think the problem may be in browser ( maybe cache, storage). Because i changed browser and it work.