Drupal form FAQ: How do I create an HTML checkbox in a Drupal form?
Assuming that you're comfortable with creating a Drupal form, you can create a Drupal form checkbox (technically a Drupal checkboxes element) as easily as this:
# an html checkbox for our drupal form # the options to display in our checkboxes $toppings = array( 'pepperoni' => t('Pepperoni'), 'black_olives' => t('Black olives'), 'veggies' => t('Veggies') ); # the drupal checkboxes form field definition $form['pizza'] = array( '#title' => t('Pizza Toppings'), '#type' => 'checkboxes', '#description' => t('Select the pizza toppings you would like.'), '#options' => $toppings, );
The checkbox is specified in this line of code:
'#type' => 'checkboxes',
Drupal form checkboxes screenshot
This Drupal checkboxes form field definition renders an HTML checkbox field that looks like this:
Note: I originally wrote this tutorial for Drupal 6, and I just confirmed that it works for Drupal 7 as well.
(If you're not comfortable with creating a Drupal module or Drupal form, please see my simple Drupal form example/tutorial.)
You can add even more fields to your Drupal checkbox definition. The fields you can add are defined in the grid at this Drupal Form API reference page.
Drupal form checkboxes form example - Summary
I hope this Drupal checkbox form example has been helpful. If you have any questions just leave a note in the Comments section below and I'll be glad to help.