Support

Account

Home Forums Front-end Issues Accept only unique values Reply To: Accept only unique values

  • Only flagging the ones that have the duplicates is much harder.

    The 4th parameter given to your filter is $input. This value contains a string that represents the current field being validating. It will look something like

    
    [acf][field_1111][0][field_2222]
    

    or possibly like this

    
    [acf][field_1111][789abc123][field_222]
    

    in the second case [789abc123] is a temporary value created when adding a field.
    In this case you’d need to match this index with the index of the array to see if it’s the row you’re checking. Honestly, I’m not sure how to do that in any easy way, and I’m not 100% confident that I have the format of $input correct

    
    foreach ($_POST['acf']['field_1111'] as $index => $row) {
      if (in_array($row['field_2222'], $list)) {
        // check $index for a match to the index value given in $input
        // if they match then set $valid to error message
        // maybe a solution, not sure, you'll have to do some testing
        if (strstr($input, '[field_1111]['.$index.'][field_2222]')) {
          $valid = 'There are duplicate '.$field['name'].' values';
        }
        // rest of code follows ....