数据检查功能不起作用

时间:2017-03-28 01:57:55

标签: php grocery-crud

我试图检查杂货店的有效日期(结束日期应该在开始日期之后)但是下面的代码不起作用它仍然保存无效日期,任何人都可以帮忙吗?

    $crud->set_rules('cardEnd','End Date','callback_valid_dates[cardEnd,cardStart]'); //dEnd before dStart
    $output = $this->grocery_crud->render();

    $output = $crud->render();
    $this->cards_output($output);


}


function cards_output($output = null)
{
    $this->load->view('cards_view.php', $output);
}

    public function check_dates($dEnd, $dStart)
{
    $var1 = explode('/', $this->input->post('dStart')); 

    $var2 = explode('/', $this->input->post('dEnd'));
    $dEnd = join('-', $var2);

    if ($dEnd >= $dStart)
    {
        return TRUE;
    }
    else
    {
        $this->form_validation->set_message('valid_date', "invalid date range end date must be after the start date ");
        return FALSE;
    }
}

1 个答案:

答案 0 :(得分:1)

check_dates()函数替换为此 -

public function check_dates($dEnd, $dStart)
{
    $var1 = strtotime($this->input->post('dStart')); 

    $var2 = strtotime($this->input->post('dEnd'));

    if ($var2 >= $var1)
    {
        return TRUE;
    }
    else
    {
        $this->form_validation->set_message('valid_date', "invalid date range end date must be after the start date ");
        return FALSE;
    }
}