我正在为前台创建一个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