2017-03-28 97 views
1

我試圖檢查雜貨中的有效日期(結束日期應該在開始日期之後),但下面的代碼不起作用,它仍然保存無效的日期,任何人都可以幫忙嗎?數據檢查功能不起作用

$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

與這 -

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; 
    } 
} 
+0

儘管如此更換check_dates()功能不起作用,無效日期仍然允許設置,不知道爲什麼。 – user3185534

+0

你有任何具體的錯誤或警告? – Ishtiak

+0

我修改了我的代碼並得到以下錯誤致命錯誤:調用未定義的函數check_dates()在E:\ EasyPHP \ EasyPHP \ data \ localweb \ wecan \ application \ controllers \ main.php 257行 – user3185534