Home › Forums › General Issues › Required field based on input other fields › Reply To: Required field based on input other fields
This is eventually the code for the Regular price being required when Deal or Discount is set to Discount (radio buttons):
add_filter('acf/validate_value/key=field_5c66e0d4f835b', 'custom_validate_regular_price_deal_one', 20, 4);
function custom_validate_regular_price_deal_one($valid, $value, $field, $input) {
// Regular price is required if Deal with or without discount has value With discount
if($_POST['acf']['field_5c7970b4aecf7'] == "Discount"){
// value of Deal with or without discount is With discount
// check value of this field;
if (empty($value)) {
$valid = 'This field is required because the field <strong>Deal with or without discount</strong> is set to <strong>With discount</strong>. Either fill in a <strong>Regular price</strong> or set your deal to <strong>Without discount</strong>.';
}
}
return $valid;
}
So all is solved! Thank you!
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.