cancel
Showing results for 
Search instead for 
Did you mean: 

Customer Login form on CMS page not working

Customer Login form on CMS page not working

I'm trying to get a login form that has been called by a CMS page to work but when tested, it redirects back to the page and doesn't log the user in.

I guess this is to do with not having the right form key as I notice the default login page has the URL format,

 

www.mydomain.com/customer/account/login/referer/blahblahblah/

and the form calls the function, getPostActionUrl() which generates this URL for the form action,

 

www.mydomain.com/customer/account/loginPost/referer/blahblahblah/

So how do I get my form to use that blahblahblah key?

The form does generate a hidden input called form_key. This isn't the same as blahblahblah though.

Here is the code of the form. Can anyone suggest how to get the blahblahblah key and where to drop it in the form code?

<div class="block block-login">
<div class="block-title">
    <strong><span><?php echo $this->__('Login') ?></span></strong>
</div>
<?php echo $this->getChildHtml('customer.form.login.extra')?><form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
    <?php echo $this->getBlockHtml('formkey'); ?>
    <div class="block-content">
        <label for="mini-login"><?php echo $this->__('Email:') ?></label>        <input type="text" name="login[username]" value="<?php echo $this->escapeHtml($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Email Address')) ?>" />
        <label for="mini-password"><?php echo $this->__('Password:') ?></label>        <input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Password')) ?>" />
        <div class="actions">            <button type="submit" class="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Login')) ?>" name="send" id="send2"><span><span><?php echo $this->__('Login') ?></span></span></button>
        </div>
    </div>
</form>
<script type="text/javascript">//<![CDATA[
var dataForm = new VarienForm('login-form', true);
//]]>
2 REPLIES 2

Re: Customer Login form on CMS page not working

Looks like form key is missing , add the below code in your form anywhere before </form> tag

 

<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />

 

Also make sure that session cookie settings are proper. Go to admin section and check setting 

at 

Admin>System>configuration>General>Web>Session Cookie Management
-- Ravindra

Re: Customer Login form on CMS page not working

Thanks for the response, Ravindra.

The code you suggested was already in the form but in this format,

<?php echo $this->getBlockHtml('formkey'); ?>


So, it wasn't that.

I did actually find another solution that worked. I added this to the form,

<?php echo $this->getChildHtml('customer.form.login.extra')?>
    <?php $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
    echo Mage::helper('core')->urlDecode($referer);
    ?>
    <form action="<?php echo Mage::getUrl('customer/account/loginPost', array('referer' => $referer)); ?>" method="post" id="login-form">

All session cookie settings were as they needed to be.

The problem now is that when the user logs in from the form, it redirects the user to the Dashboard page, not back to the page the form is on - the page in question delivers different content to the visitor depending on whether they are logged in and assigned to a particular customer group.

Thanks for all your help though.