Last active
May 1, 2017 13:30
-
-
Save aliciaduffy/ee9ad71ca79f5b4cb5593c41576e094f to your computer and use it in GitHub Desktop.
Gravity Forms Pre-Submission age check and redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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