【问题标题】:CodeIgniter Form Validation Matches LabelCodeIgniter 表单验证匹配标签
【发布时间】:2011-12-24 16:24:20
【问题描述】:

在 CodeIgniter 中运行表单验证时是否可以更改 matches 调用的输出?

我正在根据确认密码框验证密码。

array(
    'field' => 'userPassword',
    'label' => 'Password',
    'rules' => 'trim|required|matches[userConfPassword]'
)

但是当错误被触发时,它会打印出来:

The Password field does not match the userConfPassword field.

用户不知道userConfPassword 的意思,我想将其更改为更友好的内容。阅读文档我找不到方法。

【问题讨论】:

    标签: php codeigniter validation


    【解决方案1】:

    好吧,你可以覆盖默认消息:

    $this->form_validation->set_message('matches', 'the two passwords do not match|');
    

    或其他类似的消息:)。

    不过,我通常只将该消息用于“确认密码”,因此我根据需要设置了普通密码字段,仅此而已,而为了确认,我将其与输入的密码匹配,而不是相反(或两个都)。但我认为这只是品味问题。

    为了记录,写在这个paragraph of the manual

    【讨论】:

    • 完美!我从来没有想过你可以覆盖现有的消息。谢谢!
    【解决方案2】:

    此代码适用于我:

    array(
        'field'   => 'userPassword', 
        'label'   => 'Password', 
        'rules'   => 'trim|required|matches[userConfPassword]'
    ),
    array(
        'field'   => 'userConfPassword', 
        'label'   => 'Confirm Password', 
        'rules'   => 'trim|required'
    )
    

    当错误被触发时,它会打印出来:

    密码字段与确认密码字段不匹配。

    【讨论】:

      猜你喜欢
      • 2012-08-17
      • 1970-01-01
      • 2015-08-30
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 2014-10-17
      • 1970-01-01
      相关资源
      最近更新 更多