How to show a string once you submit a form in a page reloading the page? I need to create a page with a form and once you enter some values in the form and send it make some calculations and show a string under the form. Something like this image:

I know how to create a page with a form inside and I know how to show a message but in this case I need to show the string (message) under the form.
So, how to show a string once you submit a form in a page reloading the page?
Add the code to calculate and display the result in the form build

  public function buildForm(array $form, FormStateInterface $form_state) {
     $form['number1'] = array(
      '#type' =&gt; 'textfield',
    );
    $form['number2'] = array(
      '#type' =&gt; 'textfield',
    );

    $form['submit'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Sum'),
    );

    $values = $form_state-&gt;getValues();
    if (!empty($values)) {
      $result = $values['number1'] + $values['number2'];
      $form['result'] = ['#markup' =&gt; '&lt;p&gt;' . $result . '&lt;/p&gt;'];
    }

    return $form;
  }


So that the result can be included in the form rebuild when the input values are filled in.

In submit request a rebuild:

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