Last active
January 30, 2024 06:34
-
-
Save getdave/4578295 to your computer and use it in GitHub Desktop.
Gravity Forms - custom field validation function for checkboxes. Ensures all checkboxes have been checked.
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
// Replace 7 with the ID of your form and 13 with the ID of the field you want to force "all required" | |
// http://www.gravityhelp.com/documentation/page/Gform_field_validation | |
add_filter("gform_field_validation_7_13", 'validate_tcs', 10, 4); | |
function validate_tcs($result, $value, $form, $field) { | |
// Convert the checkbox input name value (returned as part of "field") | |
// into the "underscored" ID version which is found in the $_POST | |
foreach ($field['inputs'] as $input) { | |
$input_post_value = 'input_' . str_replace('.', '_', $input['id']); | |
// Validate the value | |
if ( !isset( $_POST[$input_post_value] ) ) { | |
$result["is_valid"] = false; | |
$result["message"] = "You must accept <em>all</em> of the Terms and Conditions"; | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi
how to exempt hidden check boxes that made hidden by conditional logics through java script
tried the below but not succeeded
=====================================
Below is the hidden element
Thanks