Exclude date from an exclude list.

Home Forums Quform WordPress Exclude date from an exclude list.

This topic is: resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #23246
    Legin76
    Participant

    I’ve set up a date field to exclude all days except Saturdays and Sundays. I have an exception for the 1st of January 18, which we would like users to be able to select, despite it being a Monday.

    The code I’ve used is as follows.

    
    function my_datepicker_block_days($options, $dpMinYear, $dpMaxYear, $element)
    {
        return "{
            beforeShowDay: function (date) {
                var day = date.getDay();
                if (day == 1 || day == 2 || day == 3 || day == 4 || day == 5) {
                    return [false, ''];
                } else {
                    return [true, ''];
                }
            }
        }";
    }
    add_filter('iphorm_datepicker_options_iphorm_1_3', 'my_datepicker_block_days', 10, 4);
    add_filter('iphorm_datepicker_options_iphorm_4_3', 'my_datepicker_block_days', 10, 4);
    
    function my_block_days($valid, $value, $element)
    {
        if ($valid) {
            $time = strtotime("{$value['year']}-{$value['month']}-{$value['day']}");
            $day = date('w', $time);
    
            if ($day == 1 || $day == 2 || $day == 3 || $day == 4 || $day == 5) {
                $element->addError('Please choose a Saturday or Sunday');
                $valid = false;
            }
        }
    
        return $valid;
    }
    add_filter('iphorm_element_valid_iphorm_1_3', 'my_block_days', 10, 3);
    add_filter('iphorm_element_valid_iphorm_4_3', 'my_block_days', 10, 3);
    
    #23264
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #23270
    Legin76
    Participant

    That’s worked great.. Thank you.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2025 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy