Welcome Guest, Not a member yet? Register   Sign In
TankAuth: Checking user age as a callback function
#1

[eluser]Unknown[/eluser]
I have added date of birth to the registration process for tankauth. The way I did it was 3 fields dob1, dob2, dob3 (mm,dd,yyyy). What I want now is to use a callback function to check to see if the user is 13 years or older before they can register. This is what I have attempted so far:

NOTE: This is how I implemented the date of birth if it helps/ if anyone wants to know:
http://stackoverflow.com/questions/12379...rth-issues

inside the register() function:
Code:
$this->form_validation->set_rules('dob1', 'Date of Birth Month', 'trim|required|xss_clean|exact_length[2]');
$this->form_validation->set_rules('dob2', 'Date of Birth Day', 'trim|required|xss_clean|exact_length[2]');
$this->form_validation->set_rules('dob3', 'Date of Birth Year', 'trim|required|xss_clean|exact_length[4]|callback_is_old_enough[dob1||dob2]');

and this is my callback funtion:
Code:
//Check if user is old enough
function is_old_enough($input, $dob1, $dob2) {
      $dob = $dob1.$dob2.$input;
      $date = strtotime('-13 years');
      $dateCheck = date('mdY', $date);
      if ((int)$dob < (int)$dateCheck)
          $this->form_validation->set_message('is_old_enough', 'You are not old enough to register on this site.');
      return $input;
}

Right now it acts as if the callback is not even there. Any help?
#2

[eluser]Unknown[/eluser]
I have actually figured out my issue. It was a combination of errors, but mainly a logic error. Checking if it was < when I should be checking if it was >. Here is my final solution (for now):
Code:
//Check if user is old enough
function is_old_enough($input) {
    $dob = $this->input->post('dob3').$this->input->post('dob1').$this->input->post('dob2');
    $date = (date('Y')-13).date('md');
    if ((int)$dob > (int)$date) {
        $this->form_validation->set_message('is_old_enough', 'You are not old enough to register on this site.');
        return FALSE;
    }
    return TRUE;
}

Code:
$this->form_validation->set_rules('dob1', 'Date of Birth Month', 'trim|required|xss_clean|exact_length[2]');
$this->form_validation->set_rules('dob2', 'Date of Birth Day', 'trim|required|xss_clean|exact_length[2]');
$this->form_validation->set_rules('dob3', 'Date of Birth Year', 'trim|required|xss_clean|exact_length[4]|callback_is_old_enough[]');




Theme © iAndrew 2016 - Forum software by © MyBB