How to add a user to a Users field from front-end form? 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.
You would need to do this with a plugin that provides a custom controller, which looks at the post data and modifies the entries’ Users fields accordingly.

The controller action would look something like this:

&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);
    }
}