Celebrate WordCamp Asia! - 30% OFF with coupon WC30 at checkout - Terms

How To Make Checkboxes Required

A checkbox in a WordPress web form is an input element that allows users to select one or more options from a set of choices. Checkboxes are commonly used when multiple selections are permitted. Checkboxes should not be confused with radio fields which only allow one selection to be chosen.

There are various ways of making Checkboxes required in WS Form.

Demo

Setting Individual Checkboxes As Required

To set set an individual checkbox as required:

  1. Click the Settings  icon on the checkbox field.WS Form - Checkbox - Set Required - Field Setting
  2. Click the Checkboxes tab.WS Form - Checkbox - Set Required - Checkboxes Tab
  3. Click the Required icon in the data grid on the row(s) you want to be required.WS Form - Checkbox - Set Required - Required Icon
  4. Click Save & Close at the bottom of the sidebar.
  5. Click Publish if you want to make the changes live.

Setting a Minimum or Maximum Checked Count

It is possible to choose a minimum or maximum number of checkboxes that must be checked in order to validate the field.

To do this:

  1. Click the Settings  icon on the checkbox field.WS Form - Checkbox - Set Required - Field Setting
  2. Click the Advanced tab.WS Form - Checkbox - Set Required - Advanced Tab
  3. Scroll down to the Restrictions settings.
  4. Set the Minimum Checked and/or Maximum Checked setting.WS Form - Checkbox - Set Required - Minimum Checked & Maximum Checked Settings

Inline Validation

By default, Required, Minimum Checked and Maximum Checked settings are validated when the form is submitted.

You can also show if a checkbox is validated:

  • Always
  • On field change / blur

To do this:

  1. Click the Settings  icon on the checkbox field.WS Form - Checkbox - Set Required - Field Setting
  2. Click the Advanced tab.WS Form - Checkbox - Set Required - Advanced Tab
  3. Scroll down to the Validation settings.
  4. In the Inline Validation setting:
    1. Choose Always to always show invalid feedback when a field is invalidated.
    2. Choose On Field Change or Blur to show invalid feedback when a field is changed or blurred (loses focus).

Conditional Logic

For more advanced applications, you can also check if a checkbox has been checked by using conditional logic. A simple example of this is shown below.

WS Form - Checkbox - Set Required - Conditional Logic

In this example, a checkbox row is monitored to see if it is not checked. If it is not checked, custom validity is set on the field which sets the invalid feedback shown to the user. If the checkbox is checked, the custom validity is set to blank which essentially removes the invalidity on the checkbox.