Version 1
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestInputForgeryForm.php
1 <?php
2
3 namespace Drupal\form_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Symfony\Component\HttpFoundation\JsonResponse;
8
9 class FormTestInputForgeryForm extends FormBase {
10
11   /**
12    * {@inheritdoc}
13    */
14   public function getFormId() {
15     return '_form_test_input_forgery';
16   }
17
18   /**
19    * {@inheritdoc}
20    */
21   public function buildForm(array $form, FormStateInterface $form_state) {
22     // For testing that a user can't submit a value not matching one of the
23     // allowed options.
24     $form['checkboxes'] = [
25       '#title' => t('Checkboxes'),
26       '#type' => 'checkboxes',
27       '#options' => [
28         'one' => 'One',
29         'two' => 'Two',
30       ],
31     ];
32     $form['submit'] = [
33       '#type' => 'submit',
34       '#value' => t('Submit'),
35     ];
36
37     return $form;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function submitForm(array &$form, FormStateInterface $form_state) {
44     return new JsonResponse($form_state->getValues());
45   }
46
47 }