PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Display an item in my form only at specific times.

  1. twescott
    Member

    I can see the time variable for the whole form, giving me control of start date and time for my form. This isn't quite what I need, though.

    I'd like to be able to display a specific item in my form based on a time variable. It's a basic radio box item, but I don't want my users to see it between 4 PM and Midnight.

    Thoughts?

    Posted 11 years ago on Wednesday July 18, 2012 | Permalink
  2. I can't think of a way to do this with conditional logic. You could modify the form after it's displayed, using a little jQuery (the jQuery would say, essentially, "if the current time is between 1600 and 2400, then hide this specific form field".) The hiding could be done via CSS (display:none, using a custom class for that field.)

    Or, you could have two different forms: one for 0000 to 1600, and one from 1600 to 2400. Then you can have logic in your page template or post/page to display one form or the other. That would mean there are entries in two different places. Maybe that's OK because you might want to handle them differently, different notifications?

    Maybe you could use the gform_field_css_class http://www.gravityhelp.com/documentation/page/Gform_field_css_class in a function to add a CSS class of "hidden" or "afterhours", based on the current time. It would be the same approach as with jQuery, but done in PHP in your theme's functions.php. So, if the time of day is between 1600 and 2400, then add the CSS class of "afterhours" and your theme's stylesheet would already have the style like this to hide that field:

    [css]
    .afterhours {
    	display:none;
    }

    You could get more specific with the selector but that was just a quick example.

    Do any of those ideas help?

    Posted 11 years ago on Friday July 20, 2012 | Permalink
  3. twescott
    Member

    Yes, this is quite helpful. Thank you.

    Posted 11 years ago on Friday August 3, 2012 | Permalink
  4. Did you get this working somewhere? I would like to take a look at it. Thanks.

    Posted 11 years ago on Friday August 3, 2012 | Permalink