Need help with preventing dates after 1 year from current date

Home Forums Quform WordPress Need help with preventing dates after 1 year from current date

This topic is: resolved
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #19040
    cuckoomallusa
    Participant

    Hi,

    I looked up “Preventing past date from being chosen” and i got the custom code to enter into functions.php. I customized it using this concept instead:

    function my_prevent_past_dates($valid, $value, $element)
    {
    $time = strtotime(“{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]}”);
    $eligibletime = strtotime(‘-1 year’);

    if ($time < $eligibletime) {
    $element->addError(‘Your product is not qualified for warranty service. (Product must be purchased within 1 year from today)’);
    $valid = false;

    }

    return $valid;
    }

    add_filter(‘iphorm_element_valid_iphorm_1_28’, ‘my_prevent_past_dates’, 10, 3);

    function my_datepicker_prevent_past_dates($options, $dpMinYear, $dpMaxYear, $element)
    {
    return “{
    minDate: 0,
    maxDate: new Date({$dpMaxYear}, 12 – 1, 31)
    }”;
    }
    add_filter(‘iphorm_datepicker_options_iphorm_1_28’, ‘my_datepicker_prevent_past_dates’, 10, 4);

    The problem is the error message do come out. But after the error, even if I select the correct date and resubmit, it still provides me the error message. Is there something that I need to change to make it work? There are times it works and there are times it doesn’t.

    #19049
    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.

    #19050
    cuckoomallusa
    Participant

    Thank you so much for the clarification with the code. It seems like everything is working perfectly fine after the adjusted coding you have provided for the second function. Also, is there an adjustment that I need to make so that users who inputs exact 1 year date to be valid? For example, if the current date is May 28, 2016, people who inputs May 28, 2015 will be accepted? It looks like it is still considered invalid. Can you help us out. Thank you!

    #19143
    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.

    #19151
    cuckoomallusa
    Participant

    Thank you so much!

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