gpt4 book ai didi

forms - 如何在 PrestaShop 中自定义注册表和联系表?

转载 作者:行者123 更新时间:2023-12-04 18:22:48 25 4
gpt4 key购买 nike

我需要知道如何自定义我的联系方式和注册表单。如何添加新字段(和)并使这些字段中的信息为必填或不需要。

我需要知道我必须为这些表单编辑哪些文件...

我使用 prestashop 1.4.7.0

最佳答案

这实际上是两个独立的问题,因为您处理每种情况的方式存在重大差异。

答案 1

对于注册表单,您可以编写一个包含两个钩子(Hook)处理函数的模块。这些将是:

public function hookCreateAccountForm() {}
public function hookCreateAccount($params) {}

第一个功能允许您在注册表单中添加其他字段(默认情况下,这些字段被插入到表单的末尾 authentication.tpl,尽管您可以将它们作为一个单独的组移动到其他地方)。它应该只返回您需要的附加表单 html。

第二个函数为您提供了两个参数来处理帐户创建过程。这是在标准字段被验证并创建新客户之后执行的。不幸的是,您无法使用它对附加字段进行验证(您需要使用 javascript 或覆盖 AuthController 以在 preProcess() 成员函数中执行您自己的身份验证)。在我自己的网站自定义模块之一中,我有以下内容,例如:
public function hookCreateAccount($params)
{
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$customer = $params['newCustomer'];
$address = new Address(Address::getFirstCustomerAddressId((int)$customer->id));
$membership_number = $params['_POST']['membership_number'];
....
....
}
$params['newCustomer']是数组中的标准 Prestashop 元素,包含新创建的客户对象。您的字段将位于 $params['_POST']数组 - 在我的例子中,它是一个名为 membership_number 的输入字段.

答案 2

对于联系表格,恐怕要复杂得多。最简单的 html 方法是在模板文件 contact-form.tpl 中硬编码您的附加字段。 .

要实际处理表单,您需要通过创建一个名为 ContactController.php 的文件来为 Controller 创建覆盖。在 /<web-root>/<your-optional-ps-folder>/override/controller包含类似的东西:
<?php
class ContactController extends ContactControllerCore {

function preProcess()
{
if (Tools::isSubmit('submitMessage'))
{
// The form has been submitted so your field validation code goes in here.
// Get the entered values for your fields using Tools::getValue('<field-name>')
// Flag errors by adding a message to $this->errors e.g.
$this->errors[] = Tools::displayError('I haven't even bothered to check!');
}
parent::preProcess();
if (Tools::isSubmit('submitMessage') && is_empty($this->errors))
{
// Success so now perform any addition required actions
// Note that the only indication of success is that $this->errors is empty
}
}
}

另一种方法是从 controllers\ContactController 复制整个 preProcess 函数。然后破解它,直到它完成你想要的......

关于forms - 如何在 PrestaShop 中自定义注册表和联系表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10320382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com