Add original validation rule to Advance Custom Fields

Question

I like to set validation when both fields named species1 and species2 are no values.

I set below code on function.php. Now, validation always stops update however I set value on these field.

//ACF
function my_acf_validate_value( $valid, $value, $field, $input ){

    if( !$valid ) {
        return $valid;
    }

    $value_1 = $_POST['acf']['species1'];
    $value_2 = $_POST['acf']['species2'];

    if (empty($value_1) && empty($value_2))  {
        $valid = 'Please complete at least one of the fields';
    }

    return $valid;
}
add_filter('acf/validate_value/name=species1', 'my_acf_validate_value', 10, 4);
add_filter('acf/validate_value/name=species2', 'my_acf_validate_value', 10, 4);

0
cwhiro 1 month 2021-05-12T21:08:18-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse