sách gpt4 ai đã đi

zend-framework - 复选框的自定义 Zend 错误消息

In lại 作者:行者123 更新时间:2023-12-03 18:24:56 26 4
mua khóa gpt4 Nike

我在基于 Zend 的站点中有一个表单,其中有一个必需的“条款和条件”复选框。

我设置了一条自定义消息,上面写着“您必须同意条款和条件”。

然而,因为复选框是“存在=需要”,它返回

Field 'terms' is required by rule 'terms', but the field is missing

这是 Zend 框架中定义的常量:
self::MISSING_MESSAGE => "Field '%field%' is required by rule '%rule%', but the field is missing",

我可以编辑这个常量,但这会改变所有必需复选框的错误报告。

我如何影响这种特定情况的错误报告?

1 Câu trả lời

如果您使用的是 Zend_Form_Element_Checkbox您可以customize the error messages on the Zend_Validate validators .

$form->addElement('checkbox', 'terms', array(
'label'=>'Terms and Services',
'uncheckedValue'=> '',
'checkedValue' => 'I Agree',
'validators' => array(
// array($validator, $breakOnChainFailure, $options)
array('notEmpty', true, array(
'messages' => array(
'isEmpty'=>'You must agree to the terms'
)
))
),
'required'=>true,
);

您想确保未选中的值为“空白”并且该字段为“必填”

关于zend-framework - 复选框的自定义 Zend 错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/827048/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com