title: Drupal 8 programmatically create a custom form with multiple submit buttons
body: <p>I have a custom Drupal 8 form that shows a list of users and a "check" button for each user.</p>
  
  <p>When clicking a check button, the submit handler needs to figure out which users "check" button was clicked.</p>
  
  <p>I've tried this the following way, but it always returns the id of the last element instead of the correct element.</p>
  
  <p>Is this a bug in Drupal Core Form API?</p>
  
  <p>Any other way to do this? I'm open to suggestions!</p>
  
  <p>This is just an example. What I'm actually trying to do is show a list of users that belong to a specific 'company' node. In that list there is a 'remove from company' button for each user.</p>
  
  <p><a href="http://pastebin.com/us2YFcjr" rel="noreferrer">http://pastebin.com/us2YFcjr</a></p>
  
  <pre><code>&lt;?php
  
  namespace Drupal\form_multi_submit\Form;
  
  use Drupal\Core\Form\FormBase;
  use Drupal\Core\Form\FormStateInterface;
  use Drupal\user\Entity\User;
  
  class MultiSubmitForm extends FormBase {
  
    public function getFormId() {
      return 'MultiSubmitForm';
    }
  
    public function buildForm(array $form, FormStateInterface $form_state) {
  
      // Get all users from database
      $ids = \Drupal::entityQuery('user')
        -&gt;condition('status', 1)
        -&gt;execute();
      $users = User::loadMultiple($ids);
  
      // Set form table header
      $form['users'] = array (
        '#type' =&gt; 'table',
        '#header' =&gt; array('ID', 'Remove'),
      );
  
  
      // Loop through all users
      foreach ($users as $user) {
  
        // Show user ID
        $form['users'][$user-&gt;id()]['id'] = array(
          '#type' =&gt; 'label',
          '#title' =&gt; $user-&gt;id(),
        );
  
        // Show button for each user
        $form['users'][$user-&gt;id()]['removememberbutton']['dummyNode'] = array(
          '#type' =&gt; 'submit',
          '#value' =&gt; 'Check',
          '#submit' =&gt; array([$this, 'removeMember']),
        );
      }
  
      return $form;
    }
  
  
    // Submit handler
    public function removeMember(array &amp;$form, FormStateInterface $form_state) {
      $userid = $form_state-&gt;getTriggeringElement()['#array_parents'][1];
      drupal_set_message($userid, 'status');
    }
  
    public function validateForm(array &amp;$form, FormStateInterface $form_state) {
      // Nothing to do here.
    }
  
    public function submitForm(array &amp;$form, FormStateInterface $form_state) {
      // Nothing to do here.
    }
  
  }
  </code></pre>