Is it possible to add in schedules for a form to only be available on certain hours? for example only from 8 a.m. to 22 p.m.??
Is it possible to add in schedules for a form to only be available on certain hours? for example only from 8 a.m. to 22 p.m.??
This is not built in to Gravity Forms but you can wrap the form shortcode in a plugin or function that hides content based on the time of day. That will hide the form for the hours you don't want it displayed.
Here's one:
http://wordpress.org/extend/plugins/wpsleep/
UPDATE: this did not work with a form shortcode nested inside. Looking for an alternative...
Working on it some more: would it be acceptable to just hide the form with CSS (display:none;)? That will prevent normal, casual visitors from seeing it and being able to submit it. It would still be in the source of the page. If that's OK, I accomplished that with some CSS and a little bit of code added to functions.php.
Here's the CSS to add to the bottom of your stylesheet. Be sure to change the form ID (mine is 7 here) to your form ID:
body.noshowform #gform_wrapper_7 {
display:none;
}
The bodyclass of noshowform will be added to your page, based on the time of day, by adding this to your theme's functions.php:
function noform_body_class($classes = '') {
$h = date('G');
if ($h > 7 && $h < 22) {
$classes[] = 'showform';
return $classes;
}
else {
$classes[] = 'noshowform';
return $classes;
}
}
add_filter('body_class','noform_body_class');
There is a commented version at pastie.org as well.
http://pastie.org/2290467
That will add a body class of showform when the hours are greater than 7 and less than 22 (so, the hour must be a minimum of 8 and not greater than or equal to 22, which will show the form up until 21:59:59.9999999). The next line, $classes[] = 'showform'; can be commented out once you've tested and verified that the body class is being added to your source properly based on the time of day on the server.
If that condition is not met, a body class of "noshowform" is added to the page, and then the CSS takes over and hides the form with CSS.
Let me know if you need help implementing that or are looking for a different type of solution. Thanks.
[this is a literal translation of google, sorry]
I have not tried the options mentioned as these are options for the body of the post.
Today I want to show or hide based on the time a widget located in the sidebar with a short form, perhaps there is a plugin to hide or show widgets based on the hour.
I have taken so long to comment because the reports I have come in the mail.
Thank you for the clarification. So, you want to hide a widget, which contains your form, based on the time of day? That's much easier to accomplish: all you need in that case is the Widget Logic plugin:
http://wordpress.org/extend/plugins/widget-logic/
Then in your widget settings there will be a box beneath the widget content which says "Widget logic" and a text box. In the text box, enter this conditional:
((date('G') > 7 && date('G') < 22))
That's it. This will honor the timezone setting in your WordPress admin, unlike the previous code example which relied on server time.
Let me know how that works out for you.
Thanks a lot! that works fine!
Great. Glad you got that to work. Please post if you need any more assistance.