vendredi 1 mars 2019

Making one field required when other fields are empty

I have some fields (WP ACF) on my website and I need one field required (field_5c66e017f8359) when the others are not empty.

Who can help me with the following piece of code?

add_filter('acf/validate_value/key=field_5c66e017f8359', 'custom_validate_title', 20, 4);
function custom_validate_title($valid, $value, $field, $input) {
  if (!empty($_POST['acf']['field_5c6d43781bcb1']) ||
  !empty($_POST['acf']['field_5c66e094f835a']) ||
  !empty($_POST['acf']['field_5c66e0d4f835b']) ||
  !empty($_POST['acf']['field_5c66e130f835c']) ||
  !empty($_POST['acf']['field_5c703c1fd5851'])) {
  if (empty($value)) {
  $valid = 'This field is required because you have added a value to some other field';
    }
  }
  return $valid;
}

Thank you!

Aucun commentaire:

Enregistrer un commentaire