public function buildForm(array $form, FormStateInterface $form_state) { // Only build these elements if the form is not being rebuilt if (!$form_state->isRebuilding()) { $form['name'] = [ '#type' => 'textfield', '#title' => $this->t('Name'), '#required' => true, ]; $form['email'] = [ '#type' => 'email', '#title' => $this->t('Email'), '#required' => true, ]; } $form['submit'] = [ '#type' => 'submit', '#value' => $this->t('Submit'), ]; return $form; }In this example, we only add the name and email form elements if the form is not being rebuilt. This ensures that these elements are only added when the form is first displayed, but not when it is rebuilt due to a submission. The Drupal Core Form API is part of the Drupal package library.