Skip to content

Instantly share code, notes, and snippets.

@aliciaduffy
Last active May 1, 2017 13:30
Show Gist options
  • Save aliciaduffy/ee9ad71ca79f5b4cb5593c41576e094f to your computer and use it in GitHub Desktop.
Save aliciaduffy/ee9ad71ca79f5b4cb5593c41576e094f to your computer and use it in GitHub Desktop.
Gravity Forms Pre-Submission age check and redirect
<?php
// update form id # (2)
add_action( 'gform_validation_2', 'custom_validate_not_too_old_pre_save' );
function validate_old_enough_pre_save( $validation_result ) {
$birth_date = $_POST["input_16"];
$birth_date = strtotime( $birth_date[0] . '/' . $birth_date[1] . '/' . $birth_date[2] );
// user is under 13
if ( time() < strtotime( '+13 years', $birth_date ) ) {
$validation_result["is_valid"] = false;
echo '<script type="text/javascript">
window.alert("You are too young to join this site.")
window.location.href="http://www.pbskids.com";
</script>';
}
return $validation_result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment