In this post I am going to explain how to add form key in phtml file.

Add below code snippet in Block class.

Add below code snippet in template file.

The result is as below and you will find hidden form_key field inside the form.

That’s it. Enjoy Magento 2!!