public function LearningPathCreateUserForm::submitFormAjax in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Form/LearningPathCreateUserForm.php \Drupal\opigno_learning_path\Form\LearningPathCreateUserForm::submitFormAjax()
Handles AJAX form submit.
File
- src/
Form/ LearningPathCreateUserForm.php, line 105
Class
- LearningPathCreateUserForm
- Members create form.
Namespace
Drupal\opigno_learning_path\FormCode
public function submitFormAjax(array $form, FormStateInterface $form_state) {
$response = new AjaxResponse();
// Alerts container.
$msg = [
'#prefix' => '<div id="learning_path_create_user_form_messages" class="alert-danger">',
'#suffix' => '</div>',
];
if ($form_state
->hasAnyErrors()) {
// If we have errors render it.
$msg['message'] = [
'#type' => 'status_messages',
'#weight' => -1000,
];
}
else {
$form = \Drupal::formBuilder()
->getForm('Drupal\\opigno_learning_path\\Form\\LearningPathCreateMemberForm');
$response
->addCommand(new ReplaceCommand('#learning_path_create_user_form', $form));
}
// Clear or render alerts container.
$response
->addCommand(new ReplaceCommand('#learning_path_create_user_form_messages', $msg));
return $response;
}