t('Checkboxes'), '#type' => 'checkboxes', '#options' => [ 'one' => 'One', 'two' => 'Two', ], ]; $form['submit'] = [ '#type' => 'submit', '#value' => t('Submit'), ]; return $form; } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { return new JsonResponse($form_state->getValues()); } }