Replace intro with message I have a custom module that creates a form. I want to display a message to a user, but I don't want to use the normal drupal_set_message method. I want to add a div with text and images to the top of the form after submission. 

A user may be submitting this form multiple times. So after submission, I want to still be on this page. It's just that after the form is submitted, a new div will appear at the top.

I don't really know how to detect that the form was submitted. It's similar to replacing the form and displaying a thank you message.

What is the best way to achieve that with Drupal 8?
You can request a rebuild in form submit and then add the message to the top of the form:

  public function buildForm(array $form, FormStateInterface $form_state) {

    if ($form_state-&gt;isRebuilding()) {
      $name = $form_state-&gt;getValue('name');
      $form['header'] = [
        '#type' =&gt; 'container',
        '#attributes' =&gt; ['class' =&gt; ['form-header-message', 'alert', 'alert-success']],
        'message' =&gt; [
          '#markup' =&gt; $this-&gt;t('Thank you for submitting this form, %name!', ['%name' =&gt; $name]),
        ],
      ];
    }

    $form['name'] = [
     '#type' =&gt; 'textfield',
     '#title' =&gt; $this-&gt;t('Name'),
    ];
    $form['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('Submit'),
    ];

    return $form;
  }


  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    $form_state-&gt;setRebuild();
  }