dpyic24480 2015-11-10 11:22
浏览 45
已采纳

表单规则不起作用

My controller:

public function rules()
{
    return [
        [['text'], 'required', 'message' => 'Fill in this field'],
        ['text', 'string', 'min' => 6, 'message' => 'Too short message'],
        ['text', 'validateUser']
    ];
}
public function validateUser($attribute)
{
    if (Yii::$app->user->isGuest)
        $this->addError($attribute, 'You must be logged in');
}

I have 2 problems:

1) Instead of the message 'Too short message' i see 'text field should contain at least 6 characters.'

2) validateUser not added a warning 'You must be logged in'

  • 写回答

2条回答 默认 最新

  • dongwuwei0718 2015-11-10 11:45
    关注

    Ad1. It should be ['text', 'string', 'min' => 6, 'tooShort' => 'Too short message'],

    Ad2. Are you sure this condition is true? Can you use die() here or something like that? Or this validation rule isn't even activated?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件