在多个字段之间确定验证顺序的优先级?

时间:2019-05-09 04:52:55

标签: validation cakephp cakephp-3.0

我有两个字段Car 1' and 'Car 2。我想先在表单中填写Car 1,但如果不是这样,我想填写Car 2。基本上需要填写其中一个,但{{1} }具有优先权。

为此:

Car 1

似乎Cake通过表单模板要求 ->notEmpty( 'car_id', 'A car must be selected', function ($context) { if (!empty($context['data']['car_other'])) { return false; } return true; } ) ->notEmpty( 'car_other', 'A car must be selected', function ($context) { if (!empty($context['data']['car_id'])) { return false; } return true; } ); 。我可以使用必填属性在模板端覆盖此属性,但是如果您对此进行验证,car_other似乎优先?我也在第一个other和一个->add上尝试过吗?

所以我想在初始视图中使用它:

last->true

如果您都将其提交为空:

Car 1 (Required):
  OR
Car 2: 

要通过,您必须输入1号车或2号车的值。

0 个答案:

没有答案