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
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
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
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, ) );
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
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.