Support

Account

Home Forums ACF PRO ACF Custom validation message not showing up

Unread

ACF Custom validation message not showing up

  • have two date fields where I want to make sure the “end date” is always later than the “start date”.

    I added a validation function per ACF documentation: https://www.advancedcustomfields.com/resources/acf-validate_save_post/

    It does fire on save_post, but the custom message does not display next to the field. It only says “validation failed” on the top.

    add_action('acf/validate_save_post', 'my_acf_validate_save_post');
    
    function my_acf_validate_save_post()
    {
    
        $start = $_POST['acf']['field_5fb0e816ea4fc'];
        $start = new DateTime($start);
    
        $end = $_POST['acf']['field_5fb0e83aea4fd'];
        $end = new DateTime($end);
    
        // check custom $_POST data
            if ($start > $end) {
                acf_add_validation_error('event_series_end_date', 'End Date should be later than the Start Date');
            }
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.