function AjaxFormHelperTrait::ajaxSubmit
Same name in other branches
- 9 core/lib/Drupal/Core/Ajax/AjaxFormHelperTrait.php \Drupal\Core\Ajax\AjaxFormHelperTrait::ajaxSubmit()
- 10 core/lib/Drupal/Core/Ajax/AjaxFormHelperTrait.php \Drupal\Core\Ajax\AjaxFormHelperTrait::ajaxSubmit()
- 11.x core/lib/Drupal/Core/Ajax/AjaxFormHelperTrait.php \Drupal\Core\Ajax\AjaxFormHelperTrait::ajaxSubmit()
Submit form dialog #ajax callback.
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
\Drupal\Core\Ajax\AjaxResponse An AJAX response that display validation error messages or represents a successful submission.
File
-
core/
lib/ Drupal/ Core/ Ajax/ AjaxFormHelperTrait.php, line 28
Class
- AjaxFormHelperTrait
- Provides a helper to for submitting an AJAX form.
Namespace
Drupal\Core\AjaxCode
public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
if ($form_state->hasAnyErrors()) {
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -1000,
];
$form['#sorted'] = FALSE;
$response = new AjaxResponse();
$response->addCommand(new ReplaceCommand('[data-drupal-selector="' . $form['#attributes']['data-drupal-selector'] . '"]', $form));
}
else {
$response = $this->successfulAjaxSubmit($form, $form_state);
}
return $response;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.