I have added a mini login for in topmenu using code

<?php echo $this->getLayout()->createBlock('customer/form_login')->setTemplate('customer/form/mini.login.phtml')->toHtml();  

code of my mini.login.phtml file is

<form method="post" id="login-form" action="<?php echo $this->getPostActionUrl() ?>">
    <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
            <span class="logincon"></span>
            <input type="text" name="login[username]" title="<?php echo $this->__('Enter your Email-id to Login'); ?>" id="email"  class="input-text required-entry validate-email logintex" placeholder="Email-id"/>
            <!-- <?php //echo $this->__('Email-id');     ?>    -->
            <span class="logincon"></span>
            <input type="password" title="<?php echo $this->__('Enter your password here'); ?>" name="login[password]"   id="pass" class="input-text required-entry validate-password logintex" placeholder="Password"/>
            <!-- <?php //echo $this->__('Password');     ?>  -->
        <li class="forgotpass">
            <a href="<?php echo Mage::getBaseUrl() . "customer/account/forgotpassword/"; ?>">Forgot Password?</a>
        <li class="forgotpass">
            <input type="submit" class="submit" title="<?php echo $this->__('Click here to Login'); ?>" value="<?php echo $this->__('Sign In'); ?>"/>
<script type="text/javascript">
    var dataForm = new VarienForm('login-form', true);

The problem is that even after adding form key code , customer can not login from mini login form, the reason I found for this is form key is not valid. I checked login form and mini login form have different formkey when I copied login page form key to mini login form it worked.

When I cleared all magento cache and session with browser's cookie and cache, then both the form generated same formkey and mini login worked , but after some time when try to login from another browser (even in same browser and private browsing) the issue occurs again. is there any permanant solution or alternate way to login from mini login form?

  • I think you are having problem with the topmenu block being cached, thus the invalid form key. If this block is printed in the header.phtml template with <?php echo $this->getChildHtml('topmenu'); ?>, you can try and add second argument 'false' to this call so the block won't get cached: <?php echo $this->getChildHtml('topmenu', false); ?> and try if the problem persists.
    – zokibtmkd
    Commented Mar 31, 2017 at 16:14
  • @zokibtmkd you are right , the issue is with topmenu block being cached, but passing argument 'false' make no diferrence.
    – Piyush
    Commented Apr 3, 2017 at 5:26
  • okay, I did some testing locally and will post this as an answer.
    – zokibtmkd
    Commented Apr 3, 2017 at 13:07

1 Answer 1


You will need to prevent the caching for the "catalog.topnav" block which is printed as children of the "topMenu" block. To do this, in your layout local.xml or any layout file you are using, add this:

    <reference name="catalog.topnav">
        <action method="unsetData"><key>cache_lifetime</key></action>
        <action method="unsetData"><key>cache_tags</key></action>

This should prevent the topMenu block from being cached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.