Support

Account

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!