Home › Forums › General Issues › Required field based on input other fields › Reply To: Required field based on input other fields
John, maybe you can help me one more time with a code for the Regular price which is only required when Deal or Discount (tickbox) its value is Discount. Maybe something like this?
add_filter('acf/validate_value/key=field_5c66e0d4f835b', 'custom_validate_deal1regularprice', 20, 4);
function custom_validate_deal1regularprice($valid, $value, $field, $input) {
// Discounted price is required if other fields has a value
if (!empty($_POST['acf']['field_5c6d43781bcb1'])); {
// If the other fields has a value 1
// Check value of this field;
if ($value = 1 ) {
$valid = 'This field is required because you have chosen for a deal with <strong>Discount</strong>. Either fill in a <strong>Regular price</strong> below or change your deal to a deal without discount.';
}
}
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.