php Magento 登录和注册表单一页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4626398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:44:41  来源:igfitidea点击:

Magento login and register form one page

layoutmagentophp

提问by HeinekenBluess

I am trying to combine the login form and create account form in Magento into one page. The reason is i just think the fewer pages the better. I find Magento confusing and have limited understanding of its layout and template system. I decided the easiest way to do this would be to just add the login form to the register account page. I found the login form and register form in login.phtml and register.phtml in template/customer/form/.

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

I simply copied the PHTML code from login.phtml into the register.phtml file that is in the same directory. This is what I ended up with:

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

http://pastebin.com/fpkeBsxc

http://pastebin.com/fpkeBsxc

After I fill in the email and password of an account and click login, the page returns with validation errors referring to the register account form bellow it. Basically, I'm not sure if this is because my approach is completely stupid/wrong and I can't just copy and paste code like this, or is this a simple html problem that I can't see? I think might be wrong way, as register form works. I'll post a screenshot of this in a comment, it won't let me paste more than one link. Thanks for any advice.

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

回答by Abdul Jamal

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

by this u can put html where do u want to place in customer/form/login.phtml

通过这个你可以把 html 放在你想放在 customer/form/login.phtml 的什么地方

<?php echo $this->getChildHtml('customer_form_register') ?>

回答by Gavin

In customer.xml within your theme you can move the account register block to within the login page.

在您的主题中的 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>

回答by MagePsycho

In order to merge the customer registration form with the default login form of Magento, just note the following steps:
1. Creating mini.register.phtml file
First you need to create a new template file: app/design/frontend/[your-interface]/[your-theme]/template/customer/form/mini.register.phtml
And copy the contents of default register file: app/design/frontend/base/default/template/customer/form/register.phtmlto the mini.register.phtml and customize as per your requirement.

为了将客户注册表单与 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. Including mini.register.phtml in login.phtml
First copy the file: app/design/frontend/base/default/template/customer/form/login.phtmlto your current theme as:

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

And now you need to modify the new login.phtml so that you can include the contents of mini.register.phtml.
For this, you have to use the following xml code in your layout xml file (preferably in app/design/frontend/[your-interface]/[your-theme]/layout/local.xml) as:

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

Now you can simply include the mini.register.phtml in your new login.phtml file as:

现在您可以简单地将 mini.register.phtml 包含在您的新 login.phtml 文件中,如下所示:

<?php echo $this->getChildHtml('customer_form_register2'); ?>
  1. You're done. Now clear the cache and reload the customer login page: http://your-mage-store/customer/account/login
  1. 你完成了。现在清除缓存并重新加载客户登录页面:http://your-mage-store/customer/account/login

回答by Anton S

You should do it slightly different:

你应该做的略有不同:

  1. get to know the magento layout and how it works
  2. use layout references to include both existing forms in to one template
  3. let them submit to their existing controllers
  1. 了解 magento 布局及其工作原理
  2. 使用布局引用将两个现有表单包含到一个模板中
  3. 让他们提交给他们现有的控制器