我已经为我的Magento主题创建了一个自定义布局,效果很好。到目前为止我唯一的问题是我的注册绝对没有。我尝试过搜索,但似乎只提出了如何在注册页面添加新字段的结果。我目前的代码如下:
<div id="user-login">
<span class="log-head loginfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<h2>You Already Have An Account</h2>
<p>Please login with your e-mail and password</p>
<span>
<label>Enter your E-mail address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
</span>
<input class="submit" type="submit" value="Submit">
</form>
</span>
<span class="log-head registerfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<h2>You Don't Have An Account</h2>
<p>Please enter your information and create an account</p>
<span>
<label>Email Address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
</span>
<span>
<label>Re-Enter your password:</label>
<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
</span>
<input class="submit" type="submit" value="Create Account">
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
<?php if($this->getShowAddressFields()): ?>
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
<?php endif; ?>
//]]>
</script>
</span>
</div><!--/user-login -->
我结合了注册和登录页面以适应我的设计。输入字段直接取自基本主题。在我尝试测试并创建用户之后,页面只刷新并且永远不会创建用户。如果我从后端创建用户并尝试登录页面刷新但从未登录我,也是如此。
任何帮助肯定会受到赞赏。
答案 0 :(得分:4)
您遇到问题的原因是因为两个表单都指向相同的表单操作(假设输入名称与默认magento相同)
action="<?php echo $this->getPostActionUrl()
这应该可以解决您的问题
更改此项(我不确定您使用的是哪种块类型,因此我将更改这两种操作)
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
到
<form action="<?php echo Mage::helper('customer')->getLoginPostUrl() ?>" method="post" id="login-form">
更改此
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
到
<form action="<?php echo Mage::helper('customer')->getRegisterPostUrl() ?>" method="post" id="form-validate">
如果这不起作用,则查看页面源并查看两个表单操作的指向(请参阅下面的位置,指出它们应指向的位置)。尝试将操作更改为
<?php echo Mage::getUrl() . '/customer/account/loginPost/'; ?> and <?php echo Mage::getUrl() . /customer/account/createpost/ ?>
问题原因
默认情况下,magento将注册和登录表单分为两个不同的页面,使用两个不同的块
请参阅/app/design/frontend/default/contempospace/layout/customer.xml(customer_account_create和customer_account_login)
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
两个块都有一个方法getPostActionUrl(),它指向不同的url / customer / account / loginPost /和/ customer / account / createpost /
见
/app/code/core/Mage/Customer/Block/Form/Login.php
/app/code/core/Mage/Customer/Block/Form/Register.php
答案 1 :(得分:0)
尝试使用:
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
你应该使用相同的名字来源于原始的。
答案 2 :(得分:0)
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
答案 3 :(得分:0)
每个人都对此非常有帮助(我有同样的问题)。我有点意思,但最近升级后浮出水面。问题是注册表单中没有formkey字段,只需将下面的行添加到表单中,它就开始正常运行。
<?php echo $this->getBlockHtml('formkey')?>