Home Forums Add-ons Repeater Field Validation for Date Range Reply To: Validation for Date Range

  • There’s a semicolon missing near the end. There’s no syntax checker here and I just type code straight into the message most of the time assuming that people can correct minor syntax errors when needed.

    add_filter('acf/validate_value/name=end_date', 'validate_end_date_func', 10, 4);
    function validate_end_date_func($valid, $value, $field, $input) {
      if (!$valid) {
        return $valid;
      $repeater_key = 'field_56faad2a333ab';
      $start_key = 'field_56fab49fd51ce';
      $end_key = 'field_56fab4d1d51d0';
      // extract row from input
      $row = preg_replace('/^\s*acf\[[^\]]+\]\[([^\]]+)\].*$/', '\1', $input);
      $start_value = $_POST['acf'][$repeater_key][$row][$start_key];
      $end_value = $value;
      if ($end_value <= $start_value) {
       $valid = 'end value must be greater than start value';
      return $valid;