我想使用codeigniter验证在文本字段之间进行验证。我创造了validateSchedule函数,将在回调时进行验证,但此处不进行验证工作仅在需要的条件下工作。
public function validateSchedule()
{
$fromDate=$_POST['from_date'];
$toDate=$_POST['toDate'];
if(empty($toDate) || empty($fromDate))
{
return TRUE;
}
else
{
$diffNoof_days = 10;
if(strtotime($fromDate) > strtotime($toDate)){
$this->form_validation->set_message('validateSchedule','from_date_must_be_smaller_than_to_date');
return FALSE;
}else if(strtotime($fromDate) == strtotime($toDate)){
$this->form_validation->set_message('validateSchedule','from_date_to_must_not_be_same');
return FALSE;
}else if($diffNoof_days>10)
{
$this->form_validation->set_message('validateSchedule','duration_should_not_exceed_10_days');
return FALSE;
}
}
}
$this->form_validation->set_rules('from_date','From Date','trim|required');
$this->form_validation->set_rules('to_date','To Date','trim|required|callback_validateSchedule');
您没有显示实际的回调,所以我推测您通过不删除callback_
前缀而将方法命名错误。换句话说,定义
public callback_validateSchedule($str)
{
...
}
应该是
public validateSchedule($str)
{
...
}
如果我猜错了,请显示validateSchedule()
的实际代码