acf_field_checkbox::validate_valuepublicACF 6.0.0

Validates values for the checkbox field

Method of the class: acf_field_checkbox{}

No Hooks.

Returns

true|false.

Usage

$acf_field_checkbox = new acf_field_checkbox();
$acf_field_checkbox->validate_value( $valid, $value, $field, $input );
$valid(true|false) (required)
If the field is valid.
$value(mixed) (required)
The value to validate.
$field(array) (required)
The main field array.
$input(string) (required)
The input element's name attribute.

Changelog

Since 6.0.0 Introduced.

acf_field_checkbox::validate_value() code ACF 6.0.4

function validate_value( $valid, $value, $field, $input ) {
	if ( ! is_array( $value ) || empty( $field['allow_custom'] ) ) {
		return $valid;
	}

	foreach ( $value as $value ) {
		if ( empty( $value ) ) {
			return __( 'Checkbox custom values cannot be empty. Uncheck any empty values.', 'acf' );
		}
	}

	return $valid;
}