Time Sensitive Choices with Gravity Forms

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

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. Optionally Add a Date Field
    4. Update Snippet with Parameters
  3. Parameters

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

If you want to use the above format, check show values and insert values that match the acceptable format.

Optionally Add a Date Field

By default, Time Sensitive Choices will limit times based on the current date and time. If you want your users to be able to select a date and time in the future, add a Date field to your form. The snippet will automatically limit the available times based on the selected date.

Update Snippet with Parameters

With the fields in place, the next step is to update the snippet’s parameters. Update the form_id and field_id in the snippet to match your Form ID and the Field ID for your Drop Down or Radio Button fields from above. Update date_field_id with your Date field’s ID. Set the buffer to adjust the minimum time available using PHP Relative Format.

new GW_Time_Sensitive_Choices( array(
	'form_id'       => 123,
	'field_id'      => 4,
	'date_field_id' => 5,
	'buffer'        => 60,
) );

The buffer parameter tells the snippet how many minutes 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 buffer parameter to 120.

To set the minimum time to the next hour, set the buffer to 0

Parameters

  • form_id integer required

    This is the Form ID that contains your time sensitive choices. There is no default value.

  • field_id integer required

    This is the Field ID for the field where the choices are stored. There is no default value.

  • date_field_id integer optional

    This is the Field ID for the date field that limits times based on the selected date. There is no default value.

  • buffer integer required

    Sets how far ahead to limit choices in minutes. There is no default value.

Leave a Reply

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

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Snippet

Time Sensitive Choices with Gravity Forms

This field is for validation purposes and should be left unchanged.