【问题标题】:Codeigniter 2.0.2 form validation set_rules custom error message not workingCodeigniter 2.0.2 表单验证 set_rules 自定义错误消息不起作用
【发布时间】:2020-03-28 21:34:35
【问题描述】:

我正在尝试为 codeigniter 表单验证添加自定义错误消息。

$this->load->library('form_validation');
$this->form_validation->set_rules('month', 'Month', 'trim|required', array('required' => 'You need to supply period starting month'));

但不幸的是我仍然得到了

月份字段是必需的。

错误信息。

我的ci版本是2.0.2

【问题讨论】:

    标签: php codeigniter codeigniter-form-validation


    【解决方案1】:

    在 CI 2 中,您需要设置自定义错误消息,如下所示:

    $this->form_validation->set_message('rule', 'Error Message');
    

    根据您的要求,这可能会起作用,

    $this->form_validation->set_rules('month', 'period starting month', 'trim|required');
    
    $this->form_validation->set_message('required', 'You need to supply %s');
    

    请看Docs

    set_rules 不会在您使用的版本设置验证消息

    【讨论】:

      猜你喜欢
      • 2011-10-30
      • 1970-01-01
      • 2013-01-05
      • 2021-02-02
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多