Unique form per user with custom form class Not sure if this is a related/duplicate of Generate unique form ID based on context

I am hoping I can render a unique form per user with the Form API using a custom form class.

What I've seen with \Drupal::formBuilder()-&gt;getForm(), you must provide your Form::class and this does not allow for something like:

public function getFormId() {

  $userID = \Drupal::currentUser()-&gt;id();
  $userFormID = 'form_settings' . $userID;
  return $userFormID;

}


and returns an invalid form with \Drupal::formBuilder()-&gt;getForm().

Ultimately trying to render a unique form via hook_preprocess_page() for the user to interact with.



An idea of what I have so far is a simple form with two submit items.

MYMODULE\src\Form\Form.php:

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

  $config = \Drupal::config('MYMODULE.MYMODULE_settings');

  $form['description'] = [
    '#type' =&gt; 'item',
    '#markup' =&gt; $messageMarkup,
  ];

  $form['time'] = [
    '#type' =&gt; 'hidden',
    '#default_value' =&gt; time(),
  ];

  $form['form_delay'] = [
    '#type' =&gt; 'submit',
    '#value' =&gt; $this-&gt;t('Remind Me'),
    '#submit' =&gt; ['::submitFormDelay'],
  ];

  $form['form_ignore'] = [
    '#type' =&gt; 'submit',
    '#value' =&gt; $this-&gt;t('Ignore'),
    '#submit' =&gt; ['::submitFormIgnore'],
  ];

  return $form;

}

public function submitFormDelay(array &amp;$form, FormStateInterface $form_state) {

  $values = $form_state-&gt;getValues();

  $this-&gt;configFactory-&gt;getEditable('MYMODULE.MYMODULE_settings')
    -&gt;set('time', $values['time'])
    -&gt;save();

  parent::submitForm($form, $form_state);

}

public function submitFormIgnore(array &amp;$form, FormStateInterface $form_state) {

  $this-&gt;configFactory-&gt;getEditable('MYMODULE.MYMODULE_settings')
    -&gt;set('time', NULL)
    -&gt;save();

  parent::submitForm($form, $form_state);

}


Then grabbing the time value to see if I should show the form

MYMODULE.module:

function MYMODULE_preprocess_page(&amp;$variables) {

  $config = \Drupal::config('MYMODULE.MYMODULE_settings');

  // Comes from another form controller in the module.
  $reminderDelay = $otherFormConfig-&gt;get('reminder_delay');

  $timeAtInteraction = $config-&gt;get('time') ?: NULL;

  $timeForm = \Drupal::formBuilder()
    -&gt;getForm(\Drupal\my_module\Form\Form::class);

  if ($timeAtInteraction != NULL) {

    if ($timeAtInteraction &lt; (time() - $reminderDelay)) {
      // Provide our form to page.html.twig.
      $variables['timeForm'] = $timeForm;
    }

  }

}


The form works, but of course, a single user sets it for everyone. I'd like the form/values to be unique per user.

Is it possible using the Form API?

(Working on cache contexts as suggested below, but not included above.)
Your updated post shows the issue. The issue here isn't the form, it's the underlying storage method. You are using configuration, which is for site configuration, ie configure how the site as a whole works. But you want to save values per user, not for the whole site.

What you are looking for is having a form used by all users, saving the submitted values for the user, rather than for the site.

I would suggest using the user.data service. This service lets you save data for users. You can user UserData::set() to set values, and UserData::get() to get values. Get the values in the form definition to get the default value, and set the values in the submit handlers to update them with the current values.

As a side note, if you were creating a form for configuration (which you're not), you would want to extend ConfigFormBase, which it doesn't appear you were doing, based on your code.