user3185534
user3185534

Reputation: 33

data check function does not work

I'm trying to check for a valid date in grocery crud (end date should be after start date) but the below code does not work it still saves the invalid date, can anyone help?

    $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;
    }
}

Upvotes: 1

Views: 92

Answers (1)

S M Khalilullah
S M Khalilullah

Reputation: 91

Replace the check_dates() function with this-

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

Upvotes: 1

Related Questions