CodeIgniter Forums
Triggering a validation callback function on non-existant fields - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Triggering a validation callback function on non-existant fields (/showthread.php?tid=50497)



Triggering a validation callback function on non-existant fields - El Forum - 03-28-2012

[eluser]loughlin[/eluser]
Hey,

So I had to implement a date of birth check on a site I am developing. The user gets to choose day, month and year from three separate drop-downs.

I am using this line in my code to trigger the callback 'dob_check' on submit:

$this->form_validation->set_rules('birthdate','Date of Birth','callback_dob_check');

NOTE: The actual 'birthdate' field does not exist so strictly speaking I should not be triggering a callback on it, right?

This appraoch works great and does exactly what I want however I am very curious to know is this a bad thing to do and does it introduce potential validation or security anomalies?

Any thoughts from the learned CI community out there?

Loughlin.

ps: code of the callback below :

Code:
public function dob_check()
{

  $min_age = strtotime("-13 years");
  $dob = mktime( 12, 0, 0, $this->input->post( 'dob_month' ), $this->input->post( 'dob_day' ), $this->input->post( 'dob_year' ));

  if (! checkdate($this->input->post( 'dob_month' ), $this->input->post( 'dob_day' ), $this->input->post( 'dob_year' )))
  {
   $this->form_validation->set_message('dob_check','Please fill out your date of birth fully');
   return FALSE;
  
  }
  else
  {
   if ($dob > $min_age)
   {
     $this->form_validation->set_message('dob_check','You must be over 13 to register for an account');
     return FALSE;
    
   }
   else
   {
     return TRUE;
   }
  
  }

}