Support

Account

Home Forums Front-end Issues acf_form with custom validation message Reply To: acf_form with custom validation message

  • I just did a test on one of my test sites to make sure it was working and I wasn’t mistaken about it working on the front end.

    I created to fields text1 and text2, but it should work with any 2 fields

     
    add_action('acf/validate_value/name=text1', 'validate_2_fields', 10, 4);
    function validate_2_fields($valid, $value, $field, $input) {
      $second = 'field_57192c0b5b1ee';
      if ($value != $_POST['acf'][$second]) {
        $valid = 'values must match';
      }
      return $valid;
    }
    

    There is one other thing that might cause it, and that’s a php error during the ajax call, but if you’re getting the standard error for a required field being left blank then that’s not the case.

    Check the field names/keys to make sure you’re using the right ones. The only other thing I can think of is that the fields are part of a repeater or some other nested type of field, but that doesn’t seem likely.

    The last thing to check is the field names, try changing them. The names of fields can possibly cause issues, but I’m really stretching for possible solutions.

    If everything still looks okay then you’ve probably got some other plugin or something causing a conflict. Try disabling plugins or changing themes to see if that clears up the problem.