[eluser]jbads[/eluser]
Hi what is the best way to do the following:
I have a form where users must enter 2 different dates. One for the actual date of the event they're promoting and one for the date their promotional material is to go live on my website.
For each date I would like 3 dropdowns one each for day, month and year. At the validation stage I would like to check whether the date has not already passed and that the event date comes after the promotional date.
I tried this in my controller
Code:
$e_date = $this->input->post('event_date_day').'/'.$this->input->post('event_date_month').'/'.$this->input->post('event_date_year');
$a_date = $this->input->post('active_date_day').'/'.$this->input->post('active_date_month').'/'.$this->input->post('active_date_year');
//Validate form data
$rules['event_date'] = 'trim|xss_clean|min_length[2]|callback__valid_date[$e_date]';
$rules['active_date'] = 'trim|xss_clean||min_length[2]|callback__valid_date[$a_date]';
And this in the callback function
Code:
function _valid_date($x_date){
//Prepare timestamp for entered date
$date = explode('/', $x_date);
$a_timestamp = mktime(00,00,01,$a_date[1],$a_date[0],$a_date[2]);
//Set time zone to use and create timestamp for current time
date_default_timezone_set('Pacific/Auckland');
$now = time();
//Check that the date has not already passed, that the months are not greater than 12 and the days not greater than 31
if($e_timestamp < $now || $date[1] > 12 || $date[0] > 31)
{
$this->validation->set_message('_valid_date', 'Please make you enter a valid date.');
return FALSE;
}
else
{
return TRUE;
}
}
It seems callback functions will only send the value of the current input field and wont pass the callback function the extra variable containing the date...
So It's only passing the callback the year field instead of all three fields such as 01/10/09
Is there a way to pass a callback function those variables. I have also tried setting those variables inside the callback function but then how do I check both dates individually and return the message to the correct date entry section of the form?