<p>When saving an entry field type as part of your plug-in it needs to be an array of IDs in order to work correctly. This can either be handled via a plug-in or in the form by passing the value as an array to that field handle.</p>

<p>Plug-in:</p>

<pre class="lang-php prettyprint-override"><code>$user-&gt;setContentFromPost(array(
    'entryField' =&gt; array(10)
));
$success = craft()-&gt;users-&gt;saveUser($user);
</code></pre>

<p>Front-end form:</p>

<pre class="lang-html prettyprint-override"><code>&lt;input type="hidden" name="fields[relatedEntry][]" value="{{entry.id}}"&gt;
</code></pre>

CC BY-SA 3.0
2016-04-07T13:02:53.520Z
Ah my bad, i dont think i have explained it well. The channel entries already exist, when a user updates their profile from a front end form i have created, they get to choose a channel entry from a drop down list. Problem i am having is that by selecting a channel entry and saving, the related field in their profile is remaining empty. Basically, what do i do to the form field in the user update form, for craft to relate the user to the chosen channel entry.
BillyMedia
CC BY-SA 3.0
2016-04-07T13:04:24.953Z
So you want them to be able to choose a specific entry to be related to their profile?
mcclaskiem
CC BY-SA 3.0
2016-04-07T13:04:52.500Z
That is correct.
BillyMedia
CC BY-SA 3.0
2016-04-07T13:06:30.807Z
My dropdown list of channel entries consists of the entry.id for the value, and entry.title for the label. and the field has a name of fields[myrelatedfield].
BillyMedia
CC BY-SA 3.0
2016-04-07T13:08:56.713Z
updated answer, working on a code example now!
mcclaskiem
CC BY-SA 3.0
2016-04-07T13:09:30.667Z
ah, so you cant relate a user to a channel entry from the form? as in craft doesnt handle this out the box? If i understand you correctly. i am already doing this so admins can view the channel entry to see a list of users.
BillyMedia
CC BY-SA 3.0
2016-04-07T13:12:02.577Z
see updated answer, that should get you what you need
mcclaskiem
CC BY-SA 3.0
2016-04-07T12:51:09.030Z
2016-04-07T14:05:03.793Z
2016-04-07T14:05:03.793Z
mcclaskiem
<p>I have a channel which has a relate to user field, how do I setup the front-end form which is a user details update form so they can select a channel entry from a drop down and when saved, have it relate that user to the channel entry.</p>

<form><user-profile><current-user>
How do I relate a user to a channel entry from a form?
# How do I relate a user to a channel entry from a form?

(Asked by: username_0 on 2016-04-07)

I have a channel which has a relate to user field, how do I setup the front-end form which is a user details update form so they can select a channel entry from a drop down and when saved, have it relate that user to the channel entry.

**Tags:** form, user-profile, current-user

---

## 1 answers

### Answer by username_1 on 2016-04-07. Score: 4 | Accepted answer

When saving an entry field type as part of your plug-in it needs to be an array of IDs in order to work correctly. This can either be handled via a plug-in or in the form by passing the value as an array to that field handle.
Plug-in:
$user->setContentFromPost(array(
    'entryField' => array(10)
));
$success = craft()->users->saveUser($user);

Front-end form:

> **Comments:**
> **username_0**: Ah my bad, i dont think i have explained it well. The channel entries already exist, when a user updates their profile from a front end form i have created, they get to choose a channel entry from a drop down list. Problem i am having is that by selecting a channel entry and saving, the related field in their profile is remaining empty. Basically, what do i do to the form field in the user update form, for craft to relate the user to the chosen channel entry.  
> **username_1**: So you want them to be able to choose a specific entry to be related to their profile?  
> **username_0**: That is correct.  
> **username_0**: My dropdown list of channel entries consists of the entry.id for the value, and entry.title for the label. and the field has a name of fields[myrelatedfield].  
> **username_1**: updated answer, working on a code example now!  
> **username_0**: ah, so you cant relate a user to a channel entry from the form? as in craft doesnt handle this out the box? If i understand you correctly. i am already doing this so admins can view the channel entry to see a list of users.  
> **username_1**: see updated answer, that should get you what you need  

---

