Home › Forums › Quform WordPress › past dates validation function need a fix
- This topic has 3 replies, 2 voices, and was last updated 11 years, 8 months ago by Ally.
- AuthorPosts
- March 3, 2013 at 3:46 am #3196josef777Participant
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 dayreturn “{
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
March 3, 2013 at 3:54 am #3201josef777ParticipantSorry , i couldn’t edit the post to fix the code tag
March 3, 2013 at 4:10 am #3202josef777Participantalso 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;
}
March 4, 2013 at 2:08 pm #3230AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.