CMS 页面上的 Magento 客户登录表单无法正常工作

Magento customer login form on CMS page not working

我正在尝试让 CMS 页面调用的登录表单正常工作,但在测试时,它会重定向回该页面并且不会让用户登录。

我想这是因为没有正确的表单键,因为我注意到默认登录页面有 URL 格式,

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

表单调用函数 getPostActionUrl() 为表单操作生成此 URL,

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

那么如何让我的表单使用那个 blahblahblah 键?

该表单确实生成了一个名为 form_key 的隐藏输入。不过,这与 blahblahblah 不同。

这是表格的代码。谁能建议如何获取 blahblahblah 密钥以及将其放在表单代码中的什么位置?

<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);
//]]>

通过一些研究了解了这一点。

首先,我找到了这个帖子:Magento adding referer param to getLoginPostUrl()

这为我提供了部分成功解决方案的基础。

首先,在

app/design/frontend/base/default/template/cms/cmslogin.phtml

(我为此登录表单创建的自定义文件)

我换了,

<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">

<?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">

似乎这就是让登录表单正常工作所需的全部内容。

我现在遇到的问题是,尽管 "Configuration > Customers > Customer Configuration > Login Options > Redirect Customer to Account Dashboard after Logging in" 被设置为 NO,表单正在重定向到仪表板 - 我希望它重定向回 CMS 页面(当用户登录时和特定客户组的成员,显示不同的内容)。这个会单独问的。