age gate – do not publish

/* Enter Your Custom Functions Here */
//AGE GATE FORM 8
//add_filter(‘gform_validation_8’, ‘verify_minimum_age’);

function verify_minimum_age($validation_result){
// retrieve the $form
$form = $validation_result[‘form’];
// date of birth is submitted in 3 drop menus with a parent ID of 4 in the format MM/DD/YYYY
// change the 4 here to your field ID
$dob_aray = rgpost(‘input_4’);
//if using a date drop down, the input is returned in an array as follows
$dob_month = $dob_aray[0];
$dob_day = $dob_aray[1];
$dob_year = $dob_aray[2];
//sidebar- some conditional logic to make sure that single digits are rendered with a 0 in front of them
if($dob_month < 10){ $dob_month = 0 . $dob_month; } if($dob_day < 10){ $dob_day = 0 . $dob_day; } //ok, now feed the $dob variable using the parts of the array, arranged as YYYY-MM-DD //this is where we get away with using the date drop downs as opposed to the calendar! $dob = $dob_year . '-' . $dob_month . '-' . $dob_day; // this the minimum age requirement we are validating $minimum_age = 13; // calculate age in years like a human, not a computer, based on the same birth date every year $age = date('Y') - substr($dob, 0, 4); if (strtotime(date('Y-m-d')) - strtotime(date('Y') . substr($dob, 4, 6)) < 0){ $age--; } // is $age less than the $minimum_age? if( $age < $minimum_age ){ // set the form validation to false if age is less than the minimum age $validation_result['is_valid'] = false; // find field with ID of 4 and mark it as failed validation foreach($form['fields'] as &$field){ // NOTE: replace 4 with the field you would like to mark invalid if($field['id'] == '4'){ $field['failed_validation'] = true; $field['validation_message'] = "Sorry, a parent must sign for you if you are under $minimum_age "; break; } } } // assign modified $form object back to the validation result $validation_result['form'] = $form; return $validation_result; }