$this->form_validation->run();

来源:互联网 发布:python 字典查找value 编辑:程序博客网 时间:2024/06/05 10:03

$this->form_validation->run();

Runs the validation routines. Returns boolean TRUE on success and FALSE on failure. You can optionally pass the name of the validation group via the function, as described in: 将一系列验证规则保存到一个配置文件.

CodeIgniter允许你为单个表单域创建多个验证规则,按顺序层叠在一起,你甚至可以同时预先处理表单域数据。要设置验证规则请使用set_rules() 函数:

$this->form_validation->set_rules();

上面的函数使用 三个 参数作为输入:

  1. 表单域的名字 - 就是你给表单域取的那个名字。
  2. 一个此表单域的 "人性化" 名字,它将被插入到错误信息中。例如,如果你有一个表单域叫做“user”你可能给它一个人性化名字叫做“用户名”。 注意: 如果你想让表单域的名字保存在一个语言文件里,请参考 翻译表单域名字.
  3. 为此表单域设置的验证规则。


这儿有一个示例。在你的 控制器 (form.php) 中紧接着验证初始化函数之后,添加这段代码:

$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');