Magento Tutorials

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

magento-2-invalid-form-key

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
php.ini

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

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

See more:
Magento 2 Error: One or more indexers are invalid
Warning: Your Magento folder does not have sufficient write permissions

9 Comments

Dom

A knowledge craver who always strive to be wiser everyday.

    avatar
    4 Comment threads
    5 Thread replies
    1 Followers
     
    Most reacted comment
    Hottest comment thread
    7 Comment authors
    nanCalHussain BadushaMansiDom Recent comment authors
      Subscribe  
    newest oldest most voted
    Notify of
    Hussain Badusha
    Guest
    Hussain Badusha

    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

    “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.
    Thanks,
    Hussain.

    Cal
    Guest
    Cal

    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 gives you error after clicking:
    Change
    action=”mageplaza_helloworld/post”
    To
    action=”mageplaza_helloworld/post/index”

    I hope you understand me 🙂

    nan
    Guest
    nan

    Hi,
    I am facing this in some browser.

    jyoti
    Guest
    jyoti

    Thank you.You saved my time

    Sebastian
    Guest
    Sebastian

    Thanks so much – you saved my day!