Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php \Drupal\ajax_forms_test\Form\AjaxFormsTestValidationForm::buildForm()
  2. 9 core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php \Drupal\ajax_forms_test\Form\AjaxFormsTestValidationForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php, line 25

Class

AjaxFormsTestValidationForm
Form builder: Builds a form that triggers a simple AJAX callback.

Namespace

Drupal\ajax_forms_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['driver_text'] = [
    '#title' => $this
      ->t('AJAX-enabled textfield.'),
    '#description' => $this
      ->t("When this one AJAX-triggers and the spare required field is empty, you should not get an error."),
    '#type' => 'textfield',
    '#default_value' => $form_state
      ->getValue('driver_text', ''),
    '#ajax' => [
      'callback' => 'ajax_forms_test_validation_form_callback',
      'wrapper' => 'message_area',
      'method' => 'replaceWith',
    ],
    '#suffix' => '<div id="message_area"></div>',
  ];
  $form['driver_number'] = [
    '#title' => $this
      ->t('AJAX-enabled number field.'),
    '#description' => $this
      ->t("When this one AJAX-triggers and the spare required field is empty, you should not get an error."),
    '#type' => 'number',
    '#default_value' => $form_state
      ->getValue('driver_number', ''),
    '#ajax' => [
      'callback' => 'ajax_forms_test_validation_number_form_callback',
      'wrapper' => 'message_area_number',
      'method' => 'replaceWith',
    ],
    '#suffix' => '<div id="message_area_number"></div>',
  ];
  $form['spare_required_field'] = [
    '#title' => $this
      ->t("Spare Required Field"),
    '#type' => 'textfield',
    '#required' => TRUE,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}