如何使用form_validation和CodeIgniter设置自定义错误消息 [英] How to set custom error message with form_validation And CodeIgniter

查看:297
本文介绍了如何使用form_validation和CodeIgniter设置自定义错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CodeIgniter的新手...,我试图做数组输入的表单验证...
数组名称是pages []。



and i wrote:

  $ this-> form_validation-> set_rules('pages []',' '需要'); 

如果我使用:

  $ this-> form_validation-> set_message('required','you not selected pages。'); 

它不会更改其他必需验证输入参数?



那么,如何设置错误消息只有一个验证?

解决方案

您应该更仔细地阅读用户指南的这一部分。 / p>

我不确定我可以更好地解释,但是set_message方法的第一个字段不是引用验证类型,而是引用回调函数的名称,



您需要做的是定义回调函数(本指南有一个很好的例子),您可以在其中迭代数组元素和计数检查。如果在迭代结束时计数器为0,则您设置错误消息。



希望这有帮助。


i am newbie in CodeIgniter...and i am trying to do form validation for array input... the array name is pages[].

and i wrote:

$this->form_validation->set_rules('pages[]','','required');

if i use that:

$this->form_validation->set_message('required', 'you not selected pages.');

it will not change the other "required" validation input params?

So how can i set error message only for one validation?

解决方案

It doesn't work like you stated, you should read this section of the user guide more carefully.

I'm not sure I can explain better, but the first field of the set_message method doesn't refer to the type of validation but to the callback function's name, that's the function which is doing the custom validation work.

What you need to do is define your callback function (the guide has a good example), in which you iterate through your array's elements and count what's checked. If at the end of the iteration the counter is 0 you set your error message.

Hope this helps.

这篇关于如何使用form_validation和CodeIgniter设置自定义错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆