Magento登录并注册一页

时间:2011-01-07 14:22:29

标签: layout magento php

我正在尝试将登录表单和Magento中的帐户表单合并为一个页面。原因是我认为页面越少越好。我发现Magento令人困惑,对其布局和模板系统的理解有限。我决定最简单的方法是将登录表单添加到注册帐户页面。我在login.phtml中找到了登录表单和注册表单,在template / customer / form /中找到了register.phtml。

我只是将login.phtml中的PHTML代码复制到同一目录下的register.phtml文件中。这就是我最终的结果:

http://pastebin.com/fpkeBsxc

在我填写帐户的电子邮件和密码并单击登录后,页面将返回验证错误,并参考下面的注册帐户表单。基本上,我不确定这是因为我的方法是完全愚蠢/错误的,我不能像这样复制和粘贴代码,或者这是一个我看不到的简单html问题?我认为可能是错误的方式,因为注册表格有效。我会在评论中发布这个截图,它不会让我粘贴多个链接。谢谢你的任何建议。

4 个答案:

答案 0 :(得分:8)

<reference name="content">            
    <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" />            
    </block>
</reference>

通过这个你可以把html放在customer / form / login.phtml

中的哪个位置
<?php echo $this->getChildHtml('customer_form_register') ?>

答案 1 :(得分:7)

在主题的customer.xml中,您可以将帐户注册块移动到登录页面内。

 <customer_account_login translate="label">
    <label>Customer Account Login Form</label>
    <!-- Mage_Customer -->
    <remove name="right"/>
    <remove name="left"/>

    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
    </reference>
    <reference name="content">
        <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">
            <block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
                <label>Form Fields Before</label>
            </block>
        </block> </reference>
</customer_account_login>

答案 2 :(得分:3)

要将客户注册表与Magento的默认登录表合并,请注意以下步骤:
1。创建mini.register.phtml文件
首先,您需要创建一个新的模板文件:app/design/frontend/[your-interface]/[your-theme]/template/customer/form/mini.register.phtml
并将默认寄存器文件的内容:app/design/frontend/base/default/template/customer/form/register.phtml复制到mini.register.phtml,并根据您的要求进行自定义。

<强> 2。在login.phtml中包含mini.register.phtml
首先将文件app/design/frontend/base/default/template/customer/form/login.phtml复制到您当前的主题:

app/design/frontend/[your-interface]/[your-theme]/template/customer/form/login.phtml

现在您需要修改新的login.phtml,以便包含mini.register.phtml的内容。
为此,您必须在布局xml文件中使用以下xml代码(最好在app/design/frontend/[your-interface]/[your-theme]/layout/local.xml中):

<customer_account_login translate="label">
    <reference name="content">
        <action method="unsetChild"><child>customer_form_login</child></action>
        <block type="customer/form_login" name="customer_form_login2" template="customer/form/login.phtml" >
            <block type="customer/form_register" name="customer_form_register2" template="customer/form/mini.register.phtml">
                <block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" />
            </block>
        </block>
    </reference>
    <reference name="head">
        <action method="setTitle" translate="title" module="customer"><title>Login or Create an Account</title></action>
    </reference>
</customer_account_login>

现在您只需将mini.register.phtml包含在新的login.phtml文件中即可:

<?php echo $this->getChildHtml('customer_form_register2'); ?>
  1. 你已经完成了。 现在清除缓存并重新加载客户登录页面:http://your-mage-store/customer/account/login

答案 3 :(得分:2)

你应该略有不同:

  1. 了解magento布局及其工作原理
  2. 使用布局参考将现有表单包含在一个模板中
  3. 让他们提交给现有的控制器
相关问题