Magento2 Product Save – Magento 2.2.2 Error: ‘Invalid Form Key. Please Refresh the Page’ on Product Save
magento2productsave
I add some custom option in sample product. I save this product and add changes in custom option.
But I can not save the product. and get this error,
Invalid Form Key. Please refresh the page.
Best Answer
This problem is occurred after adding more custom options and categories in the product so because php.ini file not allowed to add more custom options.
So, we need to change default settings of php.ini file.
If php version 7.1 then,
/etc/php/7.1/apache2/php.ini
If php version 7.0 then,
/etc/php/7.0/apache2/php.ini
If php version 7.2 then,
/etc/php/7.0/apache2/php.ini
Uncomment this value and update this all value in php.ini,
There is one more source for this error: a wrong cookie_domain in the configuration. As you can't login into the admin area, you can check it directly via mysql:
SELECT * FROM core_config_data WHERE path LIKE '%cookie_domain%';
You can change the value in mysql directly as well. Don't forget to clear the cache afterwards.
This bug arises due to php.ini variable "max_input_vars"
Increase it to 10000 through below php function:
ini_set('max_input_vars', 10000);
OR
Using linux command line
cd /etc/php/7.0/apache2/
vi php.ini (Open for edit and set max_input_vars=10000)
:wq(Press esc and write the mentioned command to save and exit)
sudo /etc/init.d/apache2 restart(Restart Server)
Best Answer
This problem is occurred after adding more custom options and categories in the product so because php.ini file not allowed to add more custom options.
So, we need to change default settings of php.ini file.
If php version 7.1 then,
If php version 7.0 then,
If php version 7.2 then,
Uncomment this value and update this all value in php.ini,
Then Restart Apache 2 web server, and check it.