3 namespace Drupal\form_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Symfony\Component\HttpFoundation\JsonResponse;
10 * Form constructor to test expansion of #type checkboxes and radios.
12 class FormTestCheckboxesRadiosForm extends FormBase {
17 public function getFormId() {
18 return 'form_test_checkboxes_radios';
24 public function buildForm(array $form, FormStateInterface $form_state, $customize = FALSE) {
25 // Expand #type checkboxes, setting custom element properties for some but not
27 $form['checkboxes'] = [
28 '#type' => 'checkboxes',
29 '#title' => 'Checkboxes',
34 'bar' => $this->t('<em>Bar - checkboxes</em>'),
35 '>' => "<em>Special Char</em><script>alert('checkboxes');</script>",
39 $form['checkboxes'] += [
41 '#description' => 'Enable to foo.',
49 // Expand #type radios, setting custom element properties for some but not
58 'bar' => '<em>Bar - radios</em>',
59 '>' => "<em>Special Char</em><script>alert('radios');</script>",
65 '#description' => 'Enable to foo.',
73 $form['submit'] = ['#type' => 'submit', '#value' => 'Submit'];
81 public function submitForm(array &$form, FormStateInterface $form_state) {
82 $form_state->setResponse(new JsonResponse($form_state->getValues()));