Closed (outdated)
Project:
Prepopulate
Version:
6.x-2.1
Component:
Documentation
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
4 Oct 2010 at 11:30 UTC
Updated:
14 Oct 2016 at 04:29 UTC
Jump to comment: Most recent
Hi there,
how to prepopulate an user reference list?
The fieldname is "field_user_ref[uid][uid][]"
this don't work : edit[field_user_ref][1][uid][uid]...
edit[field_user_ref][uid][uid][0]
cheers
Comments
Comment #1
johnnydarkko commentedRadiating Gnome left a great tutorial here:
http://drupal.org/node/865370#comment-3251682
Unfortunately I haven't gotten this to work, I'm still getting a blank user reference field. Any pointers to the right direction is greatly appreciated. Thanks in advance!
Comment #2
wylbur commentedThe prepopulate code for the User reference fields are different for different widget types. Here's a guide for each type.
Autocomplete field
This is the only widget type we can use to prepopulate the user reference field with the actual username, rather than the UID.
Load the page that you will prepopulate. Look at the source code for the page, and find the user reference input field in the page code. It should look something like this:
<input type="text" name="field_contractor_assigned[0][uid][uid]" id="edit-field-contractor-assigned-0-uid-uid" size="60" value="" class="form-text form-autocomplete required text" />Now use the NAME variable to build the prepopulate URL, wrap the first part of the field name in square brackets.
edit[field_contractor_assigned][0][uid][uid]=universal_builders
Select List
Unlike the autocomplete field, the select list uses the UID to select the appropriate value from the options list.
Load the page that you will prepopulate. Look at the source code for the page, and find the user reference input field in the page code. It should look something like this:
Now use the NAME variable to build the prepopulate URL, wrap the first part of the field name in square brackets. Then add another array for the value, and use the UID value:
edit[field_contractor_assigned][uid][uid][value]=150
Check boxes/Radio buttons
This widget will create a separate form element for each value.
Load the page that you will prepopulate. Look at the source code for the page, and find the user reference input field in the page code. It should look something like this:
Now use the NAME variable to build the prepopulate URL, wrap the first part of the field name in square brackets. Then add another array for the value, and use the UID value:
edit[field_contractor_assigned][uid][uid][value]=72
See if this gets your form working, and leave a comment.
Comment #3
johnnydarkko commentedThanks wylbur, but unfortunately no luck, but I think I'm just doing this wrong, hopefully you can help clarify this. I'm using conditional fields to display field_dummy so I don't know if that makes a difference.
The fields I'm trying to populate is a user reference field called field_dummy in node type "tip". I'm using views to grab the username so that I can create a button that says "tip now", and when they click it, I want the field_dummy to be prepopulated with the corresponding username So using the token [name] for username, i used the following url:
/node/add/tip?edit%5bfield_dummy%5d%5b0%5d%5buid%5d%5buid%5d=[name]
The name is field_dummy[0][uid][uid]
The field_dummy field was not prepopulated with the corresponding username. Any thoughts?
Comment #4
jbrauer commentedClosing D6 issues as it's no longer supported.