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.
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:
<input type="hidden" name="fields[relatedEntry][]" value="{{entry.id}}">
-
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 Apr 7 '16 at 13:02
-
So you want them to be able to choose a specific entry to be related to their profile? – mcclaskiem Apr 7 '16 at 13:04
-
-
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 Apr 7 '16 at 13:06
-