Magento – Magento 2 – invalid form key (add/delete from cart)

cachecartform-keymagento2PHP

I have serious problems with custom Magento 2 theme and (probably) formkey cashing. I have 2 views of exactly same e-shop.

 - View 1: Luma Theme
 - View 2: Custom Theme (Luma child) - overriding layouts, phtml, styles and javascripts

If cache is enabled and flushed everything -> adding/deleting from car works properly. After several minutes specified actions in View 2 (Custom theme) returns 302 status code and Magento redirects user to /cart page.

Now i discovered 3 ways how to "fix" this issue.

  1. Flush cache – only temporary solution for few minutes.
  2. Delete formKey validation from Magento core – totally inappropriate.
  3. Disable cache – affects performance.

I'm struggling with this problem couple of days and I will be glad for any advice.

Best Answer

Magento 2 - invalid form key occurs before of 2 reasons.

1) check your view source page, generated form_key and passing form_key are same. if not same need to fix it.

2) increase php_value max_input_vars 75000. Check your error log surely max_input_vars reached error will through.

Hope it will helpful for you

Related Topic