php - 如何将错误消息放在 Prestashop 1.7 内的表单框中?
问题描述
我正在为前台创建一个recaptcha 模块,所有代码都可以,但是错误消息会发错地方。
我使用的是 Prestashop 1.7.6.1,错误消息打印在前台顶部,我需要在表单框中打印错误消息。
我设置了这样的错误消息:modules/recaptcha/recaptcha.php
public function hookActionRecaptchaAccountValidation()
{
if (!$this->isValidateRecaptcha()) { // Logic to validate recaptcha
// Set my error message
$context->controller->errors[] = $this->l('It was not possible to validate the reCaptcha.');
}
}
我正在重写 AuthController 来执行我的自定义钩子,这将使 recaptcha 验证逻辑,这里没关系,我也放了这段代码,以防你需要。
class AuthController extends AuthControllerCore
{
public function initContent()
{
if(Tools::isSubmit('submitLogin')){
// Execute my custom hook
Hook::exec('actionRecaptchaAccountValidation');
if(sizeof($this->context->controller->errors)){ // Verify if has error message
$login_form = $this->makeLoginForm()->fillWith(
Tools::getAllValues()
);
$this->context->smarty->assign([
'login_form' => $login_form->getProxy(),
]);
$this->setTemplate('customer/authentication');
FrontController::initContent();
return;
}
}
parent::initContent();
}
}
...那么,我怎样才能像这个例子一样将错误消息放在表单框中?
请检查这张图片,我在那里准确地展示了我需要的东西。 https://i.imgur.com/Syzrf2C.png
解决方案
我认为你应该更好地研究CustomerLoginForm
类并考虑覆盖它。该submit
方法可能正是您正在寻找的。只需再添加一个验证并通过$this->errors[''][]
构造定义您的错误
推荐阅读
- sql-server - 从 SQL Server 导入时,SSIS 包在 VS 中有效,但从文件系统导入时失败(错误 SSIS.Replacement 任务未注册使用)
- php - Laravel 不会通过移动勇敢浏览器将变量保存到数据库
- algorithm - 不知道如何根据值对相邻对象进行分组
- python - 如何在 Django Rest 框架中进行条件渲染?
- node.js - Axios Gzip - 415 不支持的媒体类型和 454 未知
- c++ - 如何在 c++ 中使用在没有 Visual Studio 的 Visual Studio 中创建的 DLL
- python - 有没有办法在 discord.py 中接收其他用户对我的建议
- unity3d - 统一-iOS;有没有办法在自动导出后修改 Pod 文件依赖项?
- powershell - 通过 powershell 导出多个 AD 用户的成员资格
- qt - Qt。尝试运行项目时复制文件错误。如何修复错误以及为什么会发生?