I would like to send a message to the user on an event in the backend without a refresh. I have a 2fa login form that will send a token text. That form has a "did not recieve sms" button/link using ajax that causes the text to be sent again. I would like to inform the customer of the incoming message. There is the MessengerInterface, which you can be used to send notifications to the user. But this requires a refresh to actually show the message. ```php \Drupal::messenger()->addStatus('Some conditional message to the user'); ``` I imagine there is a way to send the message to the user using ajax/XHR? Which would not require a refresh, to inform the user of the impending text. My form has a wrapping div which I can target, the button/link has an `'#ajax'` element with, as far as I know, all the prerequisite elements: ```php '#ajax' => [ 'callback' => '::ajaxCallback', 'event' => 'click', 'wrapper' => 'twofa_wrapper', ], ``` I found [this][1] comment on the Drupal forum but using this code, with obvious replacements, does nothing apart from sending a XHR responce, visible in the network tab. The json response contains a number of things one being the html for the form which contains the message that I would like to show, but it doesn't show this content on the actual page. ```php public function ajaxCallback(array &$form, FormStateInterface $form_state) { $response = new AjaxResponse(); $message = [ '#theme' => 'status_messages', '#message_list' => \Drupal::messenger()->all(), ]; $messages = \Drupal::service('renderer')->render($message); $response->addCommand(new HtmlCommand('#twofa_wrapper', $messages)); $response->addCommand(new ReplaceCommand(null, $form)); return $response; } ``` What am I missing? **edit:** ___ The wrapping element was (is) not rendering for some reason, if I include it in the template the callback shows the messages. The problem is that I need to renew the entire form because the contents might change on the ajax call. Replacing the contents works but then the messages are no longer included. I can see that the messages are part of the response but separate from the form contents. [![enter image description here][2]][2] [1]: https://www.drupal.org/forum/support/module-development-and-code-questions/2019-05-09/how-to-rebuild-form-after-ajax#comment-13101283 [2]: https://i.sstatic.net/t19Kv.png