How do I throw values calculated back to buildForm()?

I am trying to throw back values that are calculated in submitForm() to buildForm().

How do I add more state values into it?

    /**
     * @file
     * Contains DrupalresumeFormResumeForm.
     */
    namespace DrupalresumeForm;

    use DrupalCoreFormFormBase;
    use DrupalCoreFormFormStateInterface;

    class ResumeForm extends FormBase {
      /**
       * {@inheritdoc}
       */
      public function getFormId() {
        return 'resume_form';
      }

      /**
       * {@inheritdoc}
       */
      public function buildForm(array $form, FormStateInterface $form_state) {
         $form['number1'] = array(
          '#type' => 'textfield',
          '#title' => t('number 1'),
          '#required' => TRUE,
        );

        $form['number2'] = array(
          '#type' => 'textfield',
          '#title' => t('number 2'),
          '#required' => TRUE,
        );

        $form['actions']['#type'] = 'actions';
        $form['actions']['submit'] = array(
          '#type' => 'submit',
          '#value' => $this->t('Save'),
          '#button_type' => 'primary',
        );

  $header = array(
    'total',
  );
  $output = array();
  foreach ($form_state->getValues() as $key => $value) {
     $output['total'] = $total;
  }
  $form['mytable'] = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $output,
    '#empty' => t('No Data'),
  );

        return $form;
      }


      /**
       * {@inheritdoc}
       */
      public function submitForm(array &$form, FormStateInterface $form_state) {

        foreach ($form_state->getValues() as $key => $value) {
          drupal_set_message($key . ': ' . $value);
        }

$total = $form_state->getValue('number1') * $form_state->getValue('number2');

    $form_state->setValue('total',array($total));

           }
        }


Go to Source of this post
Author Of this post: Boby
Title Of post: How do I throw values calculated back to buildForm()?
Author Link: {authorlink}