Simple on/off checkbox fields where you want the user to select or deselect a checkbox are a common requirement. Yet it is not so obvious how to create them in Drupal.
On/off checkbox fields are often used to toggle for things like:
- Accepting terms and conditions
- Accepting privacy notices
- Marking an event as cancelled
- Flagging a node or user
To create a check box, you first need to add a field with field type of Boolean. Set the widget to Single on/off checkbox.
You will then be presented with the field settings. You don’t need to change anything here.
On the next screen, select the option to Use field label instead of the “On value” as label. This will ensure that the label for the field is displayed with the field rather than the number 1.
And that is it! You now have a nice on/off checkbox.
UPDATED 6 Jan: Thanks to everyone who pointed out the boolean type and single on/off widget this out in the comments!