Sometimes in a WordPress form you will want to hide a field value. There can be many reasons for this, including:
- Hiding a field that contains a value that doesn’t need to be seen by the user, e.g. a tracking value.
- Hiding a field based on the answer of another field on the form, e.g. Show an “Other” option for a Select field.
- Hiding fields contained within a tab or a section.
Fundamentally there are two different ways of hiding field values:
- Use the Hidden field type.
- Hide a different field type (e.g. a Text field) using the Hidden setting or by using Conditional Logic.
The Hidden Field Type
If you have a form field value that should never be seen by the end user, you should use a Hidden field. You can find the Hidden field type in the Advanced grouping in the Toolbox, or use the search feature at the top of the Toolbox to search for it.
The hidden field type is different from other hiding other field
Learn more:
- The WS Form Hidden Field type.
- <input type=”hidden”> MDN web docs
Hiding Other Field Types
For fields other than the Hidden type (e.g. Text), you can use the Hidden field setting to hide the field on the form.
An example use case of using the Hidden setting would be to hide an “Other” text field for a Select field.
The default behavior of a field that has been hidden, is that it will not be included in actions such as Send Email. You can override this behavior by checking the Always Include in Actions setting (See below).
When a field is hidden, WS Form will automatically make the field no longer required. Also any other restrictions such as min and max setting are ignored. This ensures the fields are no longer validated when the form is submitted.
Using Conditional Logic to Hide & Show Fields
Any field types (other than the Hidden field type) can be hidden and shown using conditional logic. You can hide and show the field itself, the section the field is in or the tab the field is in.
When hiding a section, all fields within that section will be hidden.
When hiding a tab, all sections within that tab and their fields will be hidden.
An example condition that hides a field is shown below.
The default behavior of a field that has been hidden using conditional logic, is that it will not be included in actions such as Send Email. You can override this behavior by checking the Always Include in Actions setting (See below).
Including Fields That Have Been Hidden in Actions
Fields can be hidden by using the Hidden field settings or by using Conditional Logic.
By default when a form is submitted and actions such as Send Email run, WS Form will exclude any fields that have been hidden. The same applies to any fields in a hidden tab or hidden section.
You can override this behavior by using the Always Include in Actions setting on a field. To apply this setting:
- Click on the field settings icon.
- In the Basic tab, go to the Hidden Behavior setting.
- Check the Always Include in Actions setting.
- Click Save & Close.
Once checked, the field value will always be included when the form is submitted and WS Form processes the form actions, regardless of whether the field is hidden or visible.