Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    • Documentation
    • Support
    • Account

Time Sensitive Choices with Gravity Forms

Automatically filter times in a choice-based field based on the current time.

Last updated September 22, 2020 | Written by Scott Buchmann Leave a Comment

View CodeDownload Plugin

Overview

If you’ve ever built a form for scheduling, you know how important it is that the available times are accurate. Use this snippet to automatically limit the choices based on the current time.

  1. Overview
  2. Using the Snippet
    1. Prerequisites
    2. Add a Choice Field
    3. Update Snippet with Parameters
  3. Parameters
  4. Taking It Further

Using the Snippet

Prerequisites

Confirm that you have Gravity Forms installed and activated and that you’ve installed the snippet.

Add a Choice Field

With the snippet installed, add a Drop Down or Radio Button field to your form and set the choices to the different times you want to make available.

The snippet expects the times to be specific and in plain English. For example, all of these are acceptable:

  • 1pm
  • 1:00pm
  • 1:00 p.m.
  • 13:00

This is not acceptable:

1:00 pm – 2:00 pm

The snippet supports multiple fields in a single form.

Update Snippet with Parameters

Update the form_id and field_ids in the snippet to match your Form ID and the Field IDs for your Drop Down or Radio Button fields from above. Set the time_mod to adjust the minimum time available using PHP Relative Format.

new GW_Time_Sensitive_Choices( array(
	'form_id' => 964,
	'field_ids' => array( 10, 12, 13 ),
	'time_mod' => '+1 hours',
) );

The time_mod parameter tells the snippet how far ahead to limit choices based on the current time. For example, if you want at least a two hour lead time on appointments, you would set the time_mod parameter to +2 hours.

To set the minimum time to the next hour, set the time_mod to +0 hours

Parameters

  • form_id (integer) (required) This is the Form ID that contains your time sensitive choices. There is no default value.
  • field_ids (array) (required) This is the Field ID for the field where the choices are stored. There is no default value.
  • time_mod (string) (required) Sets how far ahead to limit choices relative to the current time in PHP relative format. There is no default value.

Taking It Further

Since a time sensitive choice-based field is going to automatically remove past times from the available choices, if your form is used to schedule any day in the future, you’ll need to be selective when you show this field.

GF Conditional Logic Dates makes it easy to automatically show this field only when appropriate. Here’s how to set that up:

Add a Date field to the form and insert the {date_mdy} merge tag into its Default Value.
Duplicate your choice-based time field. Do not apply the snippet to the duplicated field.
Use Conditional Logic to show the time sensitive field when the selected Date is today.
Set up Conditional Logic to show the duplicated field when the selected Date is not today.

Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 32+ essential add-ons for Gravity Forms with support you can count on.

  • View All Perks
  • Buy Gravity Perks

Filed Under: Snippets drop down field Radio Buttons field snippet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • How To (63)
  • News (21)
  • Plugins (14)
  • Releases (7)
  • Resource (3)
  • Snippets (58)
  • Tutorials (57)
  • Updates (104)

Recent Posts

  • How to Update Posts with Gravity Forms
  • Gravity Wiz Weekly #104
  • The Complete Guide to Using Gravity Forms With Zapier
  • Gravity Wiz Weekly #103
  • Show Active Forms by Default on Form List

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2021 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Gravity Perks
    ▼
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    ▼
    • Documentation
    • Support
    • Account