Gravity Forms – How to require all checkboxes ticked

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;
}

Related Articles

One comment on “Gravity Forms – How to require all checkboxes ticked

  1. perfect, i searched for this.

    But will this automatically work for all the forms i already made? I am asking since i have several dozens on my site and i don’t want to have to setup each one of them again….

    Thanks!
    Michael

Leave a Reply

Your email address will not be published.