1

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() ?>" />
    <ul>
        <li>
            <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');     ?>    -->
        </li>
        <li>
            <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>
        <li class="forgotpass">
            <a href="<?php echo Mage::getBaseUrl() . "customer/account/forgotpassword/"; ?>">Forgot Password?</a>
        </li>
        <li class="forgotpass">
            <input type="submit" class="submit" title="<?php echo $this->__('Click here to Login'); ?>" value="<?php echo $this->__('Sign In'); ?>"/>
        </li>
    </ul>
</form>
<script type="text/javascript">
    //<![CDATA[
    var dataForm = new VarienForm('login-form', true);
    //]]>
</script>

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?

3
  • 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
    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
    Apr 3, 2017 at 5:26
  • okay, I did some testing locally and will post this as an answer.
    – zokibtmkd
    Apr 3, 2017 at 13:07

1 Answer 1

2

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:


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

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 that you have read and understand our privacy policy and code of conduct.

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