How do I redirect users and show a message? I want to redirect users with RedirectResponse and display a message, but the message is not displayed.

$response = new RedirectResponse($url);
$response-&gt;send();


After little debugging I found that my initial (source) URL is loaded twice, and the messages (added with drupal_set_message()) are removed from the session in drupal_get_messages(). So I have no messages on my target $url.

How can I achieve this?

I'm doing it in hook_field_widget_form_alter().
Set the repeat parameter in drupal_set_message() to TRUE and it will work:

$response = new RedirectResponse($url);
$response-&gt;send();
drupal_set_message(t('My message after redirect'), 'status', TRUE);