The following code shows how to make a checkbox field in Gravity Forms require all options be ticked if the field is required.
By default, if the field is required only one needs to be ticked.
If you’re not sure where to place this code I highly recommend you read How to create a WordPress plugin for your custom functions.
Note: this uses the gform_field_validation filter that allows you to filter by form or form and field. See the Gravity Forms documentation for examples of this.
add_filter( 'gform_field_validation', 'checkbox_all_required', 10, 4 );
function checkbox_all_required( $result, $value, $form, $field ) {
if ( 'checkbox' == $field->get_input_type() && $field->isRequired ) {
foreach ( $value as $choice ) {
if ( empty( $choice ) ) {
$result['is_valid'] = false;
$result['message'] = 'All checkboxes must be ticked.';
break;
}
}
}
return $result;
}
I have several fields I want to require all checkboxes for. What would be the syntax to require all checkboxes for multiple fields in the same form?