It’s important to let your customers know exactly when your business operates - but rather than just telling them, why not actually enforce your business hours through your form? By taking advantage of some simple calculations and a bit of conditional logic, you can make your form available (or unavailable) on any day or time that you need.
1. Hide form fields during certain hours and days
One way to restrict your form’s availability to specific hours and days is with the help of sections; by putting all your form fields in a single section, you can use conditional logic to set the section (and therefore your entire form) to only appear at specific times.
First, place all of your form fields into a single section (alternatively, you can use the following method and just apply it to each individual form field). Next, select Show this Field - When from the section field settings to open up the conditional logic builder. Now, using the Advanced Editor, we can set the rules that determine when the section (aka your form) should appear.
Let’s say that our business operates from Monday through Friday from 8:00AM to 5:00PM, and on Saturdays from 8:00AM to 12:00PM. First, we’ll add the available days of the week:
=(DateTime.Today.DayOfWeek = "Monday") or (DateTime.Today.DayOfWeek = "Tuesday") or (DateTime.Today.DayOfWeek = "Wednesday") or (DateTime.Today.DayOfWeek = "Thursday") or (DateTime.Today.DayOfWeek = "Friday") or (DateTime.Today.DayOfWeek = "Saturday")
Next, we can add our hours of operation for each day using DateTime.Now. For example, Monday should look something like this (using UTC/GMT):
=(DateTime.Today.DayOfWeek = "Monday") and (DateTime.Now < DateTime.Today.AddHours(17).AddMinutes(0)) and (DateTime.Now > DateTime.Today.AddHours(8).AddMinutes(0))
So on and so forth until you get to Saturday, which has different hours of availablility:
=(DateTime.Today.DayOfWeek = "Saturday") and (DateTime.Now < DateTime.Today.AddHours(12).AddMinutes(0)) and (DateTime.Now > DateTime.Today.AddHours(8).AddMinutes(0))
These expression ensure that the section will only appear on the specified days during the specified time periods.
2. Limit selection based on time and day of week
Instead of hiding your date and time fields, you may need to have them visible on your form so your users can select a pick-up/delivery date and time. Let’s say, for example, that your Pizzeria that only delivers between 9AM to 5PM during the week, 10PM to 3PM on Saturdays, and 12PM to 3PM on Sundays. In this case, you can take advantage of the Range function in your field settings to specify the days and hours that a user is allowed to select.
First, set the Range Minimum value for your Delivery Time field to the following:
=DeliveryDate.DayOfWeek = "Saturday" ? "10:00 AM" : DeliveryDate. DayOfWeek = "Sunday" ? "12:00 PM" : "9:00 AM"
This if/then statement is simply stating that if the date selected is a Saturday, then the earliest time available is 10:00AM, and if the date is a Sunday, then the earliest time available is 12:00PM. Otherwise, the earlier time available for every other day of the week is 9:00AM.
Then, set the Range Maximum value for your Delivery Time field to the following:
=DeliveryDate.DayOfWeek = "Saturday" ? "3:00 PM" : DeliveryDate.DayOfWeek = "Sunday" ? "3:00 PM" : "5:00 PM"
Now, when the user selects a time on Friday that’s outside of the available time frame, they’ll see an error message:
You can adjust these calculations to whatever your business’ operating times are, whether they’re different for every day of the week, or just for one day. There may also be certain days of the week when you don’t deliver at all; in this case, you can go to the Delivery Date field settings and find the Show Custom Error section. With the custom error option, you can specify which day(s) that you don’t deliver in the conditional logic builder, then write your own custom error message to display:
So, when the user selects a Sunday in the Delivery Date field, they won’t be able to continue until they change the date: