[英]callback not working in codeigniter 3.0
<?php
class Form extends CI_Controller {
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('confpassword', 'Password', 'required|matches[password]', 'callback__matcherror');
//$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
//$this->form_validation->set_rules('email', 'Email', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login');
}
else
{
$this->load->view('insert_dream');
}
}
public function _matcherror() {
$this->form_validation->set_message('_matcherror', 'Passwords should match');
return FALSE;
}
}
?>
i am a newbie to codeigniter. 我是Codeigniter的新手。 The above code doesnt display passwords should match error message.
上面的代码未显示密码应与错误消息匹配。 Is something wrong with the callback or Am i missing something.
回调有问题还是我错过了什么。
You are passing callback__matcherror
as fourth parameter of set_rules
function.It should be 3rd parameter. 您将
callback__matcherror
作为set_rules
函数的第四个参数传递,它应该是第三个参数。 Use this way 用这种方式
$this->form_validation->set_rules('confpassword', 'Password', 'required|matches[password]|callback__matcherror');
Note 注意
You will get this error message if your password fields match.Because you applying 3 rule there.3rd rule(call_back_function) will apply when 2nd rule is success. 如果您的密码字段匹配,则会收到此错误消息。由于在此处应用了3条规则。当第二条规则成功时,将应用第三条规则(call_back_function)。 Your 2nd rule will valid when passwords matches.
当密码匹配时,您的第二条规则将有效。
matches[password]
will automatically check for password. 将自动检查密码。 You need not to use callback function
callback__matcherror
您不需要使用回调函数
callback__matcherror
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.