1

I have three select option list for month,day and year

<?php echo form_dropdown('dob[month]',$dates['months'],set_value('dob[month]','0'));?>
<?php echo form_dropdown('dob[day]',$dates['days'],set_value('dob[day]','0'));?>
<?php echo form_dropdown('dob[year]',$dates['years'],set_value('dob[year]','0'));?>

To validate if the entered date by the user is valid or not i am using the following rules:

$this->form_validation->set_rules('dob','date of birth','valid_dob'); 

Where valid_dob is a function defined in a My_form_validation class as follow :

public function valid_dob($dob)
{   
    if(checkdate($dob['month'],$day['day'],$day['year']))
    {
        return true;
    }
    return false;
}

But the function defined above is not executing by codeigniter,Please
let me know how can i validate a date using three drop down list.

Thanks.

Tarun
  • 3,162
  • 3
  • 29
  • 45

1 Answers1

2

You need to callback your own validation function. Add callback_ before your function name

$this->form_validation->set_rules('dob','date of birth','callback_valid_dob['.$this->input->post('dob').']');  // You can pass array to function for getting all three values month,day,year
Navneet Singh
  • 1,218
  • 11
  • 17
  • Navneet rather than using callback i have extended Form_validation class and in that i have created the method valid_dob,why this should not work? – Tarun Dec 02 '12 at 06:27
  • form_validation class is in the system/core folder . Make sure that you are not extending from application/core – Navneet Singh Dec 02 '12 at 06:35
  • 1
    Why you are not loading lib using $this->load->library('form_validation'); ? – Navneet Singh Dec 02 '12 at 06:38
  • oh my bro,I am loading the library via $this->load->library('form_validation'); ,which in turn loading my My_Form_validation and i have checked that its being loaded correctly since its working fine for other function that i have defined in My_form_validation class – Tarun Dec 02 '12 at 06:52
  • Anyway i have tried with callback as well and its not working – Tarun Dec 02 '12 at 06:56
  • oops,i was making some silly mistakes now the function in my extended library working fine,thanks for your time :) – Tarun Dec 02 '12 at 07:25