Home › Forums › Quform WordPress › Need help with preventing dates after 1 year from current date
- This topic has 4 replies, 2 voices, and was last updated 7 years, 10 months ago by cuckoomallusa.
- AuthorPosts
- May 27, 2016 at 1:49 am #19040cuckoomallusaParticipant
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.
May 27, 2016 at 10:22 pm #19049AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 28, 2016 at 1:31 am #19050cuckoomallusaParticipantThank 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!
May 30, 2016 at 9:53 pm #19143AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 31, 2016 at 7:14 pm #19151cuckoomallusaParticipantThank you so much!
- AuthorPosts
- You must be logged in to reply to this topic.