actionValidateCustomerAddressFormAfter在Prestashop的表单验证之前触发钩子

编程入门 行业动态 更新时间:2024-10-27 21:13:01
本文介绍了actionValidateCustomerAddressFormAfter在Prestashop的表单验证之前触发钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的Prestashop 1.7网站中,我有一个前端地址编辑表(允许我的客户编辑其邮政地址).在Prestashop决定用户键入的数据正确与否之后,我想执行一个钩子(例如邮政编码仅包含数字).我认为可以通过使用以下方法完成:

In my Prestashop 1.7 Website, I have a front-end address edition form (allowing my customer to edit its postal addresses). I want to execute a hook after Prestashop has decided weither the data the user typed are correct or not (e.g. postcode contains digits only). I thought it could be done by using:

$this->registerHook('actionValidateCustomerAddressFormAfter');除此之外: public function hookActionValidateCustomerAddressForm($data) { /* Here is the triggered hook */ }

但是即使用户提交了错误的数据(例如,带有至少一个字母的 邮政编码),也会执行触发的挂钩hookActionValidateCustomerAddressForm.

But the triggered hook hookActionValidateCustomerAddressForm is executed even when the user submits bad data (e.g. postcode with at least one letter).

这意味着我的程序不必等待Prestashop的数据验证.

It means that my program doesn't wait for Prestashop's data verification.

在Prestashop决定数据是否正确之后,执行此挂接的方法是什么?

What is the way to execute this hook after Prestashop decides if the data is correct?

推荐答案

此钩子是在CustomerAddessForm类的validate()函数中执行的:

This hook is executed in validate() function from CustomerAddessForm class:

public function validate() { $is_valid = true; if (($postcode = $this->getField('postcode'))) { if ($postcode->isRequired()) { $country = $this->formatter->getCountry(); if (!$country->checkZipCode($postcode->getValue())) { $postcode->addError($this->translator->trans( 'Invalid postcode - should look like "%zipcode%"', array('%zipcode%' => $country->zip_code_format), 'Shop.Forms.Errors' )); $is_valid = false; } } } if (($hookReturn = Hook::exec('actionValidateCustomerAddressForm', array('form' => $this))) !== '') { $is_valid &= (bool) $hookReturn; } return $is_valid && parent::validate(); }

此挂钩始终执行(无论表单是否有效),并且PrestaShop不会将$is_valid作为参数发送给您.因此,如果您想知道表单是否有效,唯一可以做的就是与PrestaShop进行相同的验证.

This hook is executed always (no matter if form is valid or not) and PrestaShop doesn't send you $is_valid as a parameter. So the only thing that you can do is to do the same validation than PrestaShop if you want to know if form is valid.

更多推荐

actionValidateCustomerAddressFormAfter在Prestashop的表单验证之前触发钩子

本文发布于:2023-10-13 14:34:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:钩子   表单   actionValidateCustomerAddressFormAfter   Prestashop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!