Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gravity Forms - custom field validation function for checkboxes. Ensures all checkboxes have been checked.
// Replace 7 with the ID of your form and 13 with the ID of the field you want to force "all required"
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