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.
- Using the Snippet
- Taking It Further
Using 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:
- 1:00 p.m.
This is not acceptable:
1:00 pm – 2:00 pm
Update Snippet with Parameters
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', ) );
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
- 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: