Home › Forums › General Issues › Required field based on input other fields › Reply To: Required field based on input other fields
I just fiddled with it a bit and I think this should be it?
add_filter('acf/validate_value/key=field_5c66e017f8359', 'custom_validate_title', 20, 4);
function custom_validate_title($valid, $value, $field, $input) {
// title is required if other fields has a value
if (!empty($_POST['acf']['field_5c6d43781bcb1']));
if (!empty($_POST['acf']['field_5c66e094f835a']));
if (!empty($_POST['acf']['field_5c66e0d4f835b']));
if (!empty($_POST['acf']['field_5c66e130f835c']));
if (!empty($_POST['acf']['field_5c703c1fd5851'])); {
// the other fields has a value
// check value of this field;
if (empty($value)) {
$valid = 'This field is required because you have added a value to some other field';
}
}
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!
Our guide looks into WordPress custom fields and how they stack up against the possibilities of ACF.
— Advanced Custom Fields (@wp_acf) July 18, 2022
https://t.co/hk3yibkHyk
© 2022 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.