[eluser]tim1965[/eluser]
Bretticus
Many thanks for your help i managed to get the callback working and created a couple of functions. They arent pretty but they work for me. To avoid some pain for someone in the future i will post them here.
These are for start and end date searches on a form so both fields are optional and the checks only kick in if either are filled in.
Controller
Code:
$this->form_validation->set_rules('start_date','Start Date','callback__datechecker_startdate');
$this->form_validation->set_rules('end_date','End Date','callback__datechecker_enddate');
checker for startdate
allows for start date to be blank and only checks for the presence of end date if start date contains data
Code:
function _datechecker_startdate($date)
{
$start_date= $this->input->post('start_date');
$end_date=$this->input->post('end_date');
if ( $this->input->post('start_date') == "" )
{
return TRUE;
}
if ((empty($end_date)) && (!empty($start_date)))
{
$this->form_validation->set_message('_datechecker_startdate', 'You must enter an End date, if you want to search on Date availability');
return FALSE;
}
else
{
list($day, $month, $year) = explode('/', $date);
if (checkdate($month, $day, $year))
{
return TRUE;
}
ELSE
{
$this->form_validation->set_message('_datechecker_startdate', 'The %s you entered is not a valid date, it should be in the format dd/mm/yyyy');
return FALSE;
}
}
}//end function
checker for enddate
allows for end date to be blank and only checks for the presence of end date if start date contains data
Code:
function _datechecker_enddate($date)
{
$start_date= $this->input->post('start_date');
$end_date=$this->input->post('end_date');
if ($this->input->post('end_date') == "")
{
return TRUE;
}
if ((empty($start_date)) && (!empty($end_date)))
{
$this->form_validation->set_message('_datechecker_enddate', 'You must enter a Start date, if you want to search on Date availability');
return FALSE;
}
else
{
list($day, $month, $year) = explode('/', $date);
if (checkdate($month, $day, $year))
{
return TRUE;
}
ELSE
{
$this->form_validation->set_message('_datechecker_enddate', 'The %s you entered is not a valid date, it should be in the format dd/mm/yyyy');
return FALSE;
}
}
}//end function