如何检查是否验证了第一条规则,然后无需检查第二/第三条规则,例如:
$this->form_validation->set_rules('children','Do you have children?','required');// e.g : answer no!
$this->form_validation->set_rules('son','How many sons?','required');//second rule
$this->form_validation->set_rules('daughter','How many daughter?','required');//third rule
答案 0 :(得分:0)
简单的只是放置第一条规则并在IF
$this->form_validation->set_rules('children','Do you have children?','required');
if ($this->form_validation->run() == FALSE)
{
$this->form_validation->set_rules('son','How many sons?','required');//second rule
$this->form_validation->set_rules('daughter','How many daughter?','required');//third rule
}
如果第一条规则失败则会检查第二条和第三条规则,否则如果第一条规则得到验证,则不会检查第二条和第三条规则
希望它有意义
答案 1 :(得分:0)
您可以使用codeignitor中的回调函数或在CI核心验证库中添加您自己的规则来实现此目的 这是我们如何使用回调函数 CI CallBacks
这就是我们如何拥有自己的自定义验证功能 Custom validation
答案 2 :(得分:0)
您可以使用form_validation
,如下所示
if ($this->form_validation->required($key)){
//validation did not pass
}
其中$key
为$_POST['children']
或$this->input->post('children');
TRUE / FALSE表是here