Yii2: how to use custom validation function for activeform?

前端 未结 12 1279
独厮守ぢ
独厮守ぢ 2020-12-25 14:18

In my form\'s model, I have a custom validation function for a field defined in this way

class SignupForm extends Model
{
    public function rules()
    {
          


        
12条回答
  •  执笔经年
    2020-12-25 14:29

    Are you by any chance using client side validation? If you do then you have to write a javascript function that would validate the input. You can see how they do it here:

    http://www.yiiframework.com/doc-2.0/guide-input-validation.html#conditional-validation

    Another solution would be to disable client validation, use ajax validation, that should bring back the error too.

    Also make sure that you have not overwritten the template of the input, meaning make sure you still have the {error} in there if you did overwrite it.

提交回复
热议问题