0

I want to validate from and to text fields using codeigniter validation. I have created validateSchedule function that will validate on callback but here validation is not working it is working only for required condition.

public function validateSchedule()
{       
            $fromDate=$_POST['from_date'];  
            $toDate=$_POST['toDate'];
            if(empty($toDate) || empty($fromDate))
            {
                return TRUE;
            }
            else 
            {  

            $diffNoof_days = 10;
            if(strtotime($fromDate) > strtotime($toDate)){
                $this->form_validation->set_message('validateSchedule','from_date_must_be_smaller_than_to_date');
                return FALSE;
            }else if(strtotime($fromDate) == strtotime($toDate)){
                $this->form_validation->set_message('validateSchedule','from_date_to_must_not_be_same');
                return FALSE;
            }else if($diffNoof_days>10)
            {   
                $this->form_validation->set_message('validateSchedule','duration_should_not_exceed_10_days');
                return FALSE;
            }
            }

}

$this->form_validation->set_rules('from_date','From Date','trim|required');
$this->form_validation->set_rules('to_date','To Date','trim|required|callback_validateSchedule');
user3653474
  • 3,393
  • 6
  • 49
  • 135

1 Answers1

0

You don't show the actual callback, so I'm speculating that you have named the method wrong by not removing the callback_ prefix. In other words, the definition

public callback_validateSchedule($str)
{
   ...
}

should be

public validateSchedule($str)
{
   ...
}

If I have guessed wrong please show the actual code for validateSchedule()

DFriend
  • 8,869
  • 1
  • 13
  • 26