You are here

protected function FormBuilder::elementTriggeredScriptedSubmission in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::elementTriggeredScriptedSubmission()
  2. 10 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::elementTriggeredScriptedSubmission()

Detects if an element triggered the form submission via Ajax.

This detects button or non-button controls that trigger a form submission via Ajax or some other scriptable environment. These environments can set the special input key '_triggering_element_name' to identify the triggering element. If the name alone doesn't identify the element uniquely, the input key '_triggering_element_value' may also be set to require a match on element value. An example where this is needed is if there are several // buttons all named 'op', and only differing in their value.

1 call to FormBuilder::elementTriggeredScriptedSubmission()
FormBuilder::handleInputElement in core/lib/Drupal/Core/Form/FormBuilder.php
Adds the #name and #value properties of an input element before rendering.

File

core/lib/Drupal/Core/Form/FormBuilder.php, line 1334

Class

FormBuilder
Provides form building and processing.

Namespace

Drupal\Core\Form

Code

protected function elementTriggeredScriptedSubmission($element, FormStateInterface &$form_state) {
  $input = $form_state
    ->getUserInput();
  if (!empty($input['_triggering_element_name']) && $element['#name'] == $input['_triggering_element_name']) {
    if (empty($input['_triggering_element_value']) || $input['_triggering_element_value'] == $element['#value']) {
      return TRUE;
    }
  }
  return FALSE;
}