Magento Get Form Key


Magento Get Form Key : Magento form keys are very important when you are working with forms or working on admin side. If you working with forms either on front end of back end form key is required and it’s supposed to be valid key for that instance. These keys expires so you need to keep the updated form key to perform operations.


Magento Get Form Key Syntax

Here is syntax to get form key

Form Key Syntax

Mage::getSingleton('core/session')->getFormKey();

The above syntax will give you the updated form key from the magento core session.

Note : Magento form key is very important when you are working with megento admin as the keys are required for each url and get/post requests.

When you are working with form key you get most common error message ie. invalid form key.


Invalid Form Key In Magento


This error occurs when you are using an outdated key, it says you to refresh page. Check that you are using the updated key if not then to overcome with this problem use the above session Mage::getSingleton(‘core/session’)->getFormKey(); to get updated key.


Magento Admin Secret Key

If you are working with magento admin for accessing each url you need to generate form key for each url. You can’t access any url without secret key in magento.


Let us add screct key to urls in magento.

Magento add secret key to urls

Here is syntax to append form key in admin-

Secrect Key to Urls

echo  Mage::helper("adminhtml")->getUrl("admin/sales_order_create/index");

The above syntax will generate url with secrect key.

www.example.com/index.php/admin/sales_order_create/index/key/c969fe5ee307932aa4569607ae7e5200/


Advertisements

Add Comment

📖 Read More