Validating a date against another form value

Home Forums Quform WordPress Validating a date against another form value

This topic is: not resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #5885
    ebernhard
    Participant

    Hi Guys,

    I have read the date validation guide (https://support.themecatcher.net/quform-wordpress/guides/advanced/date-validation) I would like to know if somebody knows how to make the booking period at least 6 night. So it will not be possible to book less nights.

    Hope that somebody can assist me here

    Thanks and regards,
    Eric

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

    #5926
    ebernhard
    Participant

    Hi Ally,

    Thank you for your quicj reply, I added the code to the functions.php file but I still can book for 2 nights.

    The form_id is 20 and the start date is field iphorm_20_29 and the end date is 20_47 so I changed your code to the following
    function mytheme_check_date_range($valid, $value, $element)
    {
    // Get the value of the start date element
    $startDate = $element->getForm()->getValue(‘iphorm_20_29’);

    $startDate = strtotime("{$startDate[‘year’]}-{$startDate[‘month’]}-{$startDate[‘day’]} 00:00:00");
    $sixDaysAfterStart = strtotime("+6 days", $startDate);
    $endDate = strtotime("{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]} 23:59:59");

    if ($sixDaysAfterStart > $endDate) {
    $element->addError(‘You must book at least 6 days’);
    $valid = false;
    }

    return $valid;
    }
    add_filter(‘iphorm_element_valid_iphorm_20_47’, ‘mytheme_check_date_range’, 10, 3);

    What am I doing wrong?

    Hope you can assist me once more

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

    #6073
    ebernhard
    Participant

    Hi Ally,

    I was away for a few days. I have just now send you a private email via codecanyon

    Hope you can solve the issue.

    Best regards,
    Eric

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

    #6088
    ebernhard
    Participant

    Hi Ally,

    Great thanks very much!!
    if I want this to be valid to other forms do I just copy the code and change the form id’s?

    Regards,
    Eric

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

Viewing 8 posts - 1 through 8 (of 8 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