如何将错误消息放入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

zy89380035 回答:如何将错误消息放入Prestashop 1.7内部窗体框中?

我认为您最好查看CustomerLoginForm类并考虑覆盖它。 submit方法可能正是您要寻找的方法。只需再添加一次验证并使用$this->errors[''][]构造来定义错误

本文链接:https://www.f2er.com/3130696.html

大家都在问