past dates validation function need a fix

Home Forums Quform WordPress past dates validation function need a fix

This topic is: resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3196
    josef777
    Participant

    I upgraded to version 1.4.2 and since then the form does not submit because it asks for a date in the feature to be entered and those groups are hidden with conditional logic , it was working before vesion 1.4.2 .

    the date should pass validation if it is in a hidden group like all others !

    the code i use in functions.php is

    //Date validation Start
    function mytheme_prevent_past_dates($valid, $value, $element)
    {
    $time = strtotime("{$value['year']}-{$value['month']}-{$value['day']}");

    if ($time < strtotime(‘today’)) {
    $element->addError(‘Please choose a date in the future’);
    $valid = false;
    }

    return $valid;
    }
    add_filter(‘iphorm_element_valid_iphorm_1_10’, ‘mytheme_prevent_past_dates’, 10, 3);
    add_filter(‘iphorm_element_valid_iphorm_1_25’, ‘mytheme_prevent_past_dates’, 10, 3);
    add_filter(‘iphorm_element_valid_iphorm_1_33’, ‘mytheme_prevent_past_dates’, 10, 3);
    add_filter(‘iphorm_element_valid_iphorm_1_47’, ‘mytheme_prevent_past_dates’, 10, 3);
    add_filter(‘iphorm_element_valid_iphorm_1_53’, ‘mytheme_prevent_past_dates’, 10, 3);

    function mytheme_datepicker_prevent_past_dates($options, $dpMinYear, $dpMaxYear, $element)
    {
    $year = date(‘Y’); // Today’s year
    $month = date(‘n’); // Today’s month
    $day = date(‘j’); // Today’s day

    return “{
    minDate: new Date({$year}, {$month} – 1, {$day}),
    maxDate: new Date({$dpMaxYear}, 12 – 1, 31)
    }”;
    }
    add_filter(‘iphorm_datepicker_options_iphorm_1_10’, ‘mytheme_datepicker_prevent_past_dates’, 10, 4);
    add_filter(‘iphorm_datepicker_options_iphorm_1_25’, ‘mytheme_datepicker_prevent_past_dates’, 10, 4);
    add_filter(‘iphorm_datepicker_options_iphorm_1_33’, ‘mytheme_datepicker_prevent_past_dates’, 10, 4);
    add_filter(‘iphorm_datepicker_options_iphorm_1_47’, ‘mytheme_datepicker_prevent_past_dates’, 10, 4);
    add_filter(‘iphorm_datepicker_options_iphorm_1_53’, ‘mytheme_datepicker_prevent_past_dates’, 10, 4);

    Thanks

    #3201
    josef777
    Participant

    Sorry , i couldn’t edit the post to fix the code tag

    #3202
    josef777
    Participant

    also the time function is not working , it is required even the time is in another hidden group

    // Time HH MM
    add_action('iphorm_pre_display_1', 'mytheme_fix_time', 10, 1);

    function mytheme_fix_time($form)
    {
    // Sets the default time to HH:MM
    $time = $form->getElement('iphorm_1_11');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));
    $time = $form->getElement('iphorm_1_26');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));
    $time = $form->getElement('iphorm_1_34');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));
    $time = $form->getElement('iphorm_1_48');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));
    $time = $form->getElement('iphorm_1_54');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));
    $time = $form->getElement('iphorm_1_57');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));
    }

    add_action('iphorm_element_valid_iphorm_1_11', 'mytheme_validate_time', 10, 3);
    add_action('iphorm_element_valid_iphorm_1_26', 'mytheme_validate_time', 10, 3);
    add_action('iphorm_element_valid_iphorm_1_34', 'mytheme_validate_time', 10, 3);
    add_action('iphorm_element_valid_iphorm_1_48', 'mytheme_validate_time', 10, 3);
    add_action('iphorm_element_valid_iphorm_1_54', 'mytheme_validate_time', 10, 3);
    add_action('iphorm_element_valid_iphorm_1_57', 'mytheme_validate_time', 10, 3);

    function mytheme_validate_time($valid, $value, $element)
    {
    // Validates that the time is not empty
    if ($value['hour'] === '' || $value['minute'] === '') {
    $element->addError('This field is required');
    $valid = false;
    }
    return $valid;
    }

    #3230
    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 4 posts - 1 through 4 (of 4 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