In this tutorial we will build a WordPress form that shows a message if a date chosen is on a Saturday or Sunday. This same methodology can be used to create any conditional logic that is based on the day of a week.
Demo
Tutorial
Adding Fields
First we add three fields to the form. They are as follows:
- Date / Time field
- Number field (This could also be a hidden field)
- Message field
The Date / Time field is used to select a date. The Number field will contain the day of the week. The Message field will contain the message shown if the day of the week is Saturday or Sunday.
Setting the Number Field Default Value
The following is added to the Default Value setting of the Number field.
#text(#field_date_format(123, "N"))
This syntax is used to insert the day of a date field:
Breaking this down:
#text
keeps the value updated dynamically. If the Date / Time field is changed, WS Form will update this value.#field_date_format
returns a formatted date for a particular field ID. In this tutorial the Date / Time field has an ID of 123 and “N” returns the day of the week from 1 (Monday) through 7 (Sunday).
Creating the Conditional Logic
The following is an example of the conditional logic that will show the Message field if the chosen Date / Time is a Saturday or Sunday.