[eluser]php_princess[/eluser]
With my signup form, my users enter the day, month, and year of their birthdate separately. PHP is what puts these three strings together into one string called $birthdate. I wrote a validation check that looks at a birthdate and sees if the person is at least 13 years old. However, I can't use it with $this->form_validation->set_rules() because that method only looks in $this->input->post(). How can I get it to look in $birthdate? Here is my relevant code:
Where the three strings are put together in my controller:
Code:
$birthdate = $this->input->post('birth_year').'-'.$this->input->post('birth_month').'-'.$this->input->post('birth_day');
The validation check in MY_form_validation.php
Code:
public function check_age($age, $minimum) //returns false if personis under the minimum specified age
{
$cur_date = new DateTime(date('Y-m-d', mktime()));
$birth_date= new DateTime($age);
$interval = $cur_date->diff($birth_date);
return ( $interval->y >= $minimum) ? FALSE : TRUE;
}
check_age is going to accept input like this:
Code:
$this->form_validation->set_rules('birthdate', 'Birth Date', 'check_age[13]')
**Actually it also checks a little more than this but I wanted to keep my post simple and to the point.