Home › Forums › General Issues › Conditional logic applied to 'Required' › Reply To: Conditional logic applied to 'Required'
That is exactly it. Thank you!
My example:
add_filter('acf/validate_value/name=event_category', 'validate_empty_fields', 10, 4);
function validate_empty_fields( $valid, $value, $field, $input ){
// bail early if value is already invalid
if( !$valid ) {return $valid; }
$is_event_public = $_POST['acf']['field_55420ab8d2eb2']; // This field is a checkbox
if($is_event_public){
if(!$value){
$valid = __('This field is required for public events');
}
}
return $valid;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.