Skip to main content
Category:

How do I define checkboxes in a form in Drupal 9

 

in Drupal 8 & 9 form api you can define checkboxes like below:

$form['high_school']['tests_taken'] = [
  '#type' => 'checkboxes',
  '#options' => array('SAT' => $this->t('SAT'), 'ACT' => $this->t('ACT')),
  '#title' => $this->t('Title'),
];

 

Example 2:

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

$form['items_selected'] = [
  '#type' => 'checkboxes',
  '#options' => $options,
  '#title' => $this->t('Title'),
];

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook