Answer the question
In order to leave comments, you need to log in
How to hide ajax form in hook_form_alter after submit?
Hello, I am changing the login form, making it ajax, everything is fine, but how can I make it so that after a successful submission the form disappears and only a welcome message remains, now both the form and the message remain
function mymodule_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'user_login_form') {
$form['system_messages'] = [
'#markup' => '<div id="' . Html::getClass($form_id) . '-messages"></div>',
'#weight' => -100,
];
$form['name']['#attributes'] = ['style' => 'background-color: #0a6fb4'];
$form['actions']['submit']['#ajax'] = [
'callback' => 'ajax_callback',
'event' => 'click',
'progress' => [
'type' => 'throbber',
],
];
$form['#submit'][] = 'mymodule_form_submit';
}
}
function ajax_callback(array &$form, FormStateInterface $form_state) {
// код не по теме
}
function mymodule_form_submit(&$form, FormStateInterface $form_state) {
\Drupal::messenger()
->addMessage((t('Привет')));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question