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.
14 class FormTestCheckboxesRadiosForm extends FormBase {
19 public function getFormId() {
20 return 'form_test_checkboxes_radios';
26 public function buildForm(array $form, FormStateInterface $form_state, $customize = FALSE) {
27 // Expand #type checkboxes, setting custom element properties for some but not
29 $form['checkboxes'] = [
30 '#type' => 'checkboxes',
31 '#title' => 'Checkboxes',
36 'bar' => $this->t('<em>Bar - checkboxes</em>'),
37 '>' => "<em>Special Char</em><script>alert('checkboxes');</script>",
41 $form['checkboxes'] += [
43 '#description' => 'Enable to foo.',
51 // Expand #type radios, setting custom element properties for some but not
60 'bar' => '<em>Bar - radios</em>',
61 '>' => "<em>Special Char</em><script>alert('radios');</script>",
67 '#description' => 'Enable to foo.',
75 $form['submit'] = ['#type' => 'submit', '#value' => 'Submit'];
83 public function submitForm(array &$form, FormStateInterface $form_state) {
84 $form_state->setResponse(new JsonResponse($form_state->getValues()));