How do I define checkboxes in a form? I have a form where I need to add a checkboxes field. The purpose of this form is to display some values from the database. I would like to display id from my database table as checkbox' value (when "active" = 1) and url as checkbox' labels.

The database table's structure is the following.

id | uid | hash          | url          | active

1  | 1   | myhashstring1 | example_url  | 1
2  | 1   | myhashstring3 | example_url4 | 1
3  | 1   | myhashstring2 | example_url2 | 0


How can I achieve this?
As per Drupal 8 form api you can define checkboxes like below:

$form['high_school']['tests_taken'] = array(
  '#type' =&gt; 'checkboxes',
  '#options' =&gt; array('SAT' =&gt; $this-&gt;t('SAT'), 'ACT' =&gt; $this-&gt;t('ACT')),
  '#title' =&gt; $this-&gt;t('What standardized tests did you take?'),
  ...
);


In your case you can update above code

$options = array();
$options[1] = 'example_url';
$options[2] = 'example_url4';
$options[3] = 'example_url2';

$form['items_selected'] = array(
  '#type' =&gt; 'checkboxes',
  '#options' =&gt; $options,
  '#title' =&gt; $this-&gt;t('Title you want to give'),
  ...
);