Magento Expert Forum - Improve your Magento experience

Results 1 to 2 of 2

How to Add Form Key in Magento 2

  1. #1
    Junior Member
    Join Date
    Nov 2022
    CA, USA
    Thanked 0 Times in 0 Posts

    Default How to Add Form Key in Magento 2

    Cross-site request forgery in Magento 2 can be avoided by adding a form key to the Phtml code.

    According to Wikipedia, cross-site request forgery results in
    "An attacker deceives an innocent end-user into sending a web request that they did not intend. This could result in actions being taken on the website, such as unintentional client or server data leaking, session state modification, or account manipulation.

    When you add a form key to Magento 2, you protect your website from spammers trying to post to your forms from other websites pretending to be you!

    By putting the solution into practice, Magento will be instructed to look for a layout block named "formkey," output it and store it for the duration of a user session.

    Visit here for a programmatical solution.

    View more threads in the same category:

  2. #2
    Junior Member
    Join Date
    Sep 2018
    Oman, Muscat
    Thanked 2 Times in 2 Posts


    In this post I will make sense of how for add structure key in phtml record. Add underneath code bit in Block class.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts