Home › Forums › Quform WordPress › Datepicker – blockout weekends and specific days
- This topic has 7 replies, 3 voices, and was last updated 10 years, 1 month ago by
pik70.
- AuthorPosts
- January 14, 2013 at 12:00 am #2153
kbrands
ParticipantHi
I am trying to blockout all weekends and public holidays (specific dates) in the datepicker. I have reviewed and applied the code offered here https://support.themecatcher.net/quform-wordpress/guides/advanced/date-validation however my problem is I can get either all weekends bolcked out OR the specific dates I have specified but I can’t get both working together.
I did notice that the last paragraph under “Prevent specific dates from being chosen” it states:
“Note that the datepicker options hooks will not inherit the options from any previous hooks. So if you plan on using both steps above to block past dates and specific dates, you should move the datepicker options into one function.”Is this the same for what I am trying to do – all weekends + specific days/dates? If so, could you advise how I would combine these into one function as I am unsure how.
Your help would be greatly appreciated.
Thank You! K
January 14, 2013 at 9:43 am #2158Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 18, 2013 at 5:45 am #2314kbrands
ParticipantThank you for your reply. I apologise for the delay in mine…changed hosts and lost access for a few days. I tried adding the code you provided but I fear I have not put it in the right spot as the specific days are blocked out but not the weekends 🙁 I have included the full function code I currently have below…I would appreciate it if you could advise how I should be structuring it as I find myself a bit clueless at this point… Thank you!
function mytheme_get_dates_to_disable()
{
return array(
‘2013-1-26’,
‘2013-1-28’,
‘2013-3-29’,
‘2013-4-1’,
‘2013-4-25’,
‘2013-6-10’,
‘2013-7-10’,
‘2013-12-25’,
‘2013-12-26’,
‘2014-1-1’,
‘2014-1-27’,
‘2014-4-1’,
‘2014-4-18’,
‘2014-4-21’,
‘2014-4-25’,
‘2014-6-9’,
‘2014-10-6’,
‘2014-12-25’,
‘2014-12-26’,
‘2015-1-1’,
‘2015-1-26’,
‘2015-4-3’,
‘2015-4-6’,
‘2015-6-8’,
‘2015-10-5’,
‘2015-12-25’,
‘2015-12-28’,
‘2016-1-1’,
‘2016-1-26’,
‘2016-3-25’,
‘2016-3-28’,
‘2016-4-25’,
‘2016-6-13’,
‘2016-10-3’,
‘2016-12-26’,
‘2016-12-27’
);
}function mytheme_prevent_specific_dates($valid, $value, $element)
{
if ($valid) {
$disabledDates = mytheme_get_dates_to_disable();
$submittedDate = “{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]}”;if (in_array($submittedDate, $disabledDates)) {
$element->addError(‘That date is not available’);
$valid = false;
}
}return $valid;
}
add_filter(‘iphorm_element_valid_iphorm_1_23’, ‘mytheme_prevent_specific_dates’, 10, 3);function mytheme_datepicker_prevent_specific_dates($options, $dpMinYear, $dpMaxYear, $element)
{
return “{
beforeShowDay: function (date) {
if (quformDisabledDates) {
for (var i = 0; ivar quformDisabledDates = ;
<?php
}
add_action('wp_head', 'mytheme_print_dates_to_disable');
return "{
beforeShowDay: function (date) {
if (quformDisabledDates) {
for (var i = 0; i < quformDisabledDates.length; i++) {
var parts = quformDisabledDates[i].split('-');
if (date.getFullYear() == parts[0] && (date.getMonth()+1) == parts[1] && date.getDate() == parts[2]) {
return [false];
}
}
}var day = date.getDay();
if (day == 0 || day == 6) {
// It's a Sunday or Saturday, block the date
return [false, ''];
} else {
return [true, ''];
}
}
}";January 18, 2013 at 9:02 am #2319Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 18, 2013 at 10:00 am #2321kbrands
ParticipantHere it is…sorry…I’m a bit of a newb 🙂
function mytheme_get_dates_to_disable()
{
return array(
'2013-1-26',
'2013-1-28',
'2013-3-29',
'2013-4-1',
'2013-4-25',
'2013-6-10',
'2013-7-10',
'2013-12-25',
'2013-12-26',
'2014-1-1',
'2014-1-27',
'2014-4-1',
'2014-4-18',
'2014-4-21',
'2014-4-25',
'2014-6-9',
'2014-10-6',
'2014-12-25',
'2014-12-26',
'2015-1-1',
'2015-1-26',
'2015-4-3',
'2015-4-6',
'2015-6-8',
'2015-10-5',
'2015-12-25',
'2015-12-28',
'2016-1-1',
'2016-1-26',
'2016-3-25',
'2016-3-28',
'2016-4-25',
'2016-6-13',
'2016-10-3',
'2016-12-26',
'2016-12-27'
);
}function mytheme_prevent_specific_dates($valid, $value, $element)
{
if ($valid) {
$disabledDates = mytheme_get_dates_to_disable();
$submittedDate = "{$value['year']}-{$value['month']}-{$value['day']}";if (in_array($submittedDate, $disabledDates)) {
$element->addError('That date is not available');
$valid = false;
}
}return $valid;
}
add_filter('iphorm_element_valid_iphorm_1_23', 'mytheme_prevent_specific_dates', 10, 3);function mytheme_datepicker_prevent_specific_dates($options, $dpMinYear, $dpMaxYear, $element)
{
return "{
beforeShowDay: function (date) {
if (quformDisabledDates) {
for (var i = 0; i < quformDisabledDates.length; i++) {
var parts = quformDisabledDates[i].split('-');
if (date.getFullYear() == parts[0] && (date.getMonth()+1) == parts[1] && date.getDate() == parts[2]) {
return [false];
}
}
}
return [true];
}
}";
}
add_filter('iphorm_datepicker_options_iphorm_1_23', 'mytheme_datepicker_prevent_specific_dates', 10, 4);
function mytheme_print_dates_to_disable()
{
?>
<script type="text/javascript">
var quformDisabledDates = <?php echo json_encode(mytheme_get_dates_to_disable()); ?>;
</script>
<?php
}
add_action('wp_head', 'mytheme_print_dates_to_disable');function mytheme_datepicker_block_days($options, $dpMinYear, $dpMaxYear, $element)
{
return "{
beforeShowDay: function (date) {
var day = date.getDay();
if (day == 0 || day == 6) {
// It's a Sunday or Saturday, block the date
return [false, ''];
} else {
return [true, ''];
}
}
}";
}
add_filter('iphorm_datepicker_options_iphorm_1_23', 'mytheme_datepicker_block_days', 10, 4);
function mytheme_block_days($valid, $value, $element)
{
if ($valid) {
$time = strtotime("{$value['year']}-{$value['month']}-{$value['day']}");
$day = date('w', $time);if ($day == 0 || $day == 6) {
$element->addError('Please choose another day');
$valid = false;
}
}return $valid;
}
add_filter('iphorm_element_valid_iphorm_1_23', 'mytheme_block_days', 10, 3);
January 20, 2013 at 12:49 pm #2329Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
January 20, 2013 at 3:49 pm #2330kbrands
ParticipantThank you Ally! That code worked a treat!!! 🙂
March 11, 2015 at 10:35 pm #14543pik70
ParticipantHi,
I have two forms, in the first form I blocked the thursdays with your code “Blocking entire days”, and it’s work. I need block the wednesday in the second form, when I put again the code in the functions.php, just change the unique ID and the days, doesn’t work and my web show me a error.
This is my code:
//FIRST BLOCK//
function mytheme_datepicker_block_days($options, $dpMinYear, $dpMaxYear, $element)
{
return “{
beforeShowDay: function (date) {
var day = date.getDay();
if (day == 0 || day == 1 || day == 2 || day == 3 || day == 5 || day == 6) {
// Esta fecha no opera este tour.
return [false, ”];
} else {
return [true, ”];
}
}
}”;
}
add_filter(‘iphorm_datepicker_options_iphorm_206_64’, ‘mytheme_datepicker_block_days’, 10, 4);function mytheme_block_days($valid, $value, $element)
{
if ($valid) {
$time = strtotime(“{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]}”);
$day = date(‘w’, $time);if (day == 0 || day == 1 || day == 2 || day == 3 || day == 5 || day == 6) {
$element->addError(‘Este tour tiene salidas los días JUEVES’);
$valid = false;
}
}return $valid;
}
add_filter(‘iphorm_element_valid_iphorm_206_64’, ‘mytheme_block_days’, 10, 3);//SECOND BLOCK//
function mytheme_datepicker_block_days($options, $dpMinYear, $dpMaxYear, $element)
{
return “{
beforeShowDay: function (date) {
var day = date.getDay();
if (day == 0 || day == 1 || day == 2 || day == 4 || day == 5 || day == 6) {
// Esta fecha no opera este tour.
return [false, ”];
} else {
return [true, ”];
}
}
}”;
}
add_filter(‘iphorm_datepicker_options_iphorm_207_64’, ‘mytheme_datepicker_block_days’, 10, 4);function mytheme_block_days($valid, $value, $element)
{
if ($valid) {
$time = strtotime(“{$value[‘year’]}-{$value[‘month’]}-{$value[‘day’]}”);
$day = date(‘w’, $time);if (day == 0 || day == 1 || day == 2 || day ==43 || day == 5 || day == 6) {
$element->addError(‘Este tour tiene salidas los días MIERCOLES’);
$valid = false;
}
}return $valid;
}
add_filter(‘iphorm_element_valid_iphorm_207_64’, ‘mytheme_block_days’, 10, 3);Regards,
- AuthorPosts
- You must be logged in to reply to this topic.