Support

Account

Home Forums General Issues add_filter “acf/validate_save_post” and acf_add_validation_error Reply To: add_filter “acf/validate_save_post” and acf_add_validation_error

  • Here is an example for people who want to understand:

    
    add_filter('acf/validate_value/key=field_65067bde5086e', 'checkEmails', 10, 4);
    add_filter('acf/validate_value/key=field_65067e4f26db1', 'checkEmails', 10, 4);
    
    function checkEmails($valid, $value, $field, $input_name){
    
        if(!isset($_POST['acf']['field_65067bd15086d'])) return $valid;
    
        $email = $_POST['acf']['field_65067bd15086d']['field_65067bde5086e'];
        $confirmEmail = $_POST['acf']['field_65067bd15086d']['field_65067e4f26db1'];
    
        if(
            !filter_var($email, FILTER_VALIDATE_EMAIL)
    
            ||
    
            $email !== $confirmEmail
        ){
    
            return 'test';
        }
    
        return $valid;
    }