Answers.Body: <p>You would need to do this with a plugin that provides a custom <a href="https://craftcms.com/docs/plugins/controllers" rel="nofollow">controller</a>, which looks at the post data and modifies the entries’ Users fields accordingly.</p>
  
  <p>The controller action would look something like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  $entryIds = craft()-&gt;request-&gt;getPost('entries');
  
  if ($entryIds &amp;&amp; is_array($entryIds))
  {
      // Get the current user's ID
      $currentUserId = craft()-&gt;userSession-&gt;getUser()-&gt;id;
  
      // Fetch the entries
      $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
      $criteria-&gt;id = $entryIds;
      $entries = $criteria-&gt;find();
  
      foreach ($entries as $entry)
      {
          // Update the Users field value with the current user's ID
          $userIds = $entry-&gt;myUsersField-&gt;ids();
          $userIds[] = $currentUserId;
  
          $entry-&gt;setContentFromPost(array(
              'myUsersField' =&gt; $userIds;
          ));
  
          craft()-&gt;entries-&gt;saveEntry($entry);
      }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-04T15:09:06.530Z
Answers.Text: Thanks for the reply, Brandon. What I meant was a "Users field type", not a field in a user's profile. What I am trying to do is update a Users field in a channel entry, with a front end form that would add a logged in user's ID to  a specific channel entry, via a Users field.
Answers.UserDisplayName: Roi Agneta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-04T23:00:41.700Z
Answers.Text: @RoiAgneta Ah sorry, misunderstood. I just updated my answer :)
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-02T14:20:27.747Z
Answers.LastActivityDate: 2016-04-04T22:59:35.587Z
Answers.LastEditDate: 2016-04-04T22:59:35.587Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>Is it possible to update an entry’s Users field from the front-end? If so, how would you go about it?</p>
  
  <p>The situation is this: training events are created and then posted for members to bid on for a limited number of spots. Logged in members review the available events and add their name (would use their ID) to each event of interest. Admins then manually chose a select few from all submissions.</p>
  
  <p>I know I can do this by adding their IDs to a text field in the event section, and then using Split to create an array, but the Users field approach is much more elegant and offers more flexibility.</p>
  
Tags: <users><relations>
Title: How to add a user to a Users field from front-end form?
ThreadText: # How to add a user to a Users field from front-end form?
  
  (Asked by: username_0 on 2016-04-01)
  
  Is it possible to update an entry’s Users field from the front-end? If so, how would you go about it?
  
  The situation is this: training events are created and then posted for members to bid on for a limited number of spots. Logged in members review the available events and add their name (would use their ID) to each event of interest. Admins then manually chose a select few from all submissions.
  
  I know I can do this by adding their IDs to a text field in the event section, and then using Split to create an array, but the Users field approach is much more elegant and offers more flexibility.
  
  **Tags:** users, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-04-02. Score: 2
  
  You would need to do this with a plugin that provides a custom [controller](https://craftcms.com/docs/plugins/controllers), which looks at the post data and modifies the entries’ Users fields accordingly.
  
  The controller action would look something like this:
  
  ```php
  <?php
  
  $entryIds = craft()->request->getPost('entries');
  
  if ($entryIds && is_array($entryIds))
  {
      // Get the current user's ID
      $currentUserId = craft()->userSession->getUser()->id;
  
      // Fetch the entries
      $criteria = craft()->elements->getCriteria(ElementType::Entry);
      $criteria->id = $entryIds;
      $entries = $criteria->find();
  
      foreach ($entries as $entry)
      {
          // Update the Users field value with the current user's ID
          $userIds = $entry->myUsersField->ids();
          $userIds[] = $currentUserId;
  
          $entry->setContentFromPost(array(
              'myUsersField' => $userIds;
          ));
  
          craft()->entries->saveEntry($entry);
      }
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for the reply, username_1. What I meant was a "Users field type", not a field in a user's profile. What I am trying to do is update a Users field in a channel entry, with a front end form that would add a logged in user's ID to  a specific channel entry, via a Users field.  
  > **username_1**: @username_0 Ah sorry, misunderstood. I just updated my answer :)  
  
  ---
  
  