Welcome Guest, Not a member yet? Register   Sign In
how to use form validation to compare date? - if not possible accept a parallel solution.
#5

[eluser]LuckyFella73[/eluser]
Hi spectruman,

I didn't test the script but you could do it this way:

1. set up a hidden form field (called "hidden_field" in my script)

and validate:
Code:
$this->form_validation->set_rules('dateStart', 'Start Date', 'trim|required');
$this->form_validation->set_rules('dateEnd', 'Date endFim', 'trim |required');
$this->form_validation->set_rules('timeStart', 'Start Time', 'trim|required');
$this->form_validation->set_rules('timeEnd', 'End Time', 'trim|required');
  
$this->form_validation->set_rules('hidden_field', 'Notice', 'callback_compareDataTime');
  

function compareDataTime()
{
    $dateStart = $this->input->post('dateStart'); // match your input-field-name here
    $timeStart = $this->input->post('timeStart');
    $dateEnd = $this->input->post('dateEnd');
    $timeEnd = $this->input->post('timeEnd');
  
    if ( ($timeStart == '12:00' && $timeEnd == '14:00') || ($timeStart == '14:00' && $timeEnd == '12:00') ||
              ($timeStart == '12:00' && $timeEnd <= $timeStart) || ($timeStart >= '12:00' && $timeEnd <= $timeStart) ||
              ($timeStart <= '12:00' && $timeEnd < $timeStart && $dateStart == $dateEnd) || ($timeStart == $timeEnd && $dateStart == $dateEnd) )
          {
        return false;
    }
    else
    {
        return true;
    }
}

This way you just check your callback function one time - what should be enough.


Messages In This Thread
how to use form validation to compare date? - if not possible accept a parallel solution. - by El Forum - 04-19-2010, 07:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB