By kordou on
Hi
I have a node type with some cck fields and among theme there is a user reference cck field.
I'd like to ask if there is a way to auto complete the user reference from the link, so i will have a view with an arsument of user name or user id to give the value to user reference field
thanks
Comments
_
Haven't tried it, but what about http://drupal.org/project/ur_autocomplete?
With the help of this
With the help of this module:
http://drupal.org/project/prepopulate
You should be able to do this. It may feel a little more kludgy than most Drupal fixes, but it works, and that's the important thing. ;)
I'm using this exact trick with a node reference, so it should work for a user reference, too. I'm actually using it in a view, but you should be able to use it anywhere that you can reference the uid of the person you want your user reference field to link to.
One thing to keep in mind is that the user and node reference cck fields store the ID numbers, not the names, so the data you're looking for is the uid for the user.
In your case, you're in a view. Here's what I would do:
1. Install the prepopulate module
2. In your view, add a new field that calls up the uid you're looking for
3. in views, you want to select the "rewrite the output of this field" and "output this field as a link" option.
4. The rewritten output of the field is the link text, or even an image that you want to use if you prefer an icon.
4. Here's where it gets kludgy. The "link path" field. You're going to put in a link to the node creation form and include the prepopulation information.
In my own case, I found that I needed to use websafe codes rather than the actual characters, which makes it even uglier, but it's not too bad once you get your head around it:
So, assuming a content type called "exampletype" and a field called "selectuser", your link will look something like this:
node/add/exampletype?edit%5bfield_selectuser%5d%5b0%5d%5bnid%5d=[uid]
(%5b is "[", and %5d is "]", so this is the url-safe translation of:
"node/add/timeticket?edit[field_selectuser][0][nid]=[uid]")
So, assuming you've got the right UID, that *should* prepopulate the selectuser field with the right user.
I hope that helps!
This is a great tutorial,
This is a great tutorial, thanks Radiating Gnome!
I tried this out and I'm getting no luck with prepopulate 6.x-2.1 and cck 6.x-2.9.
given the nodetype is 'exampletype' and the user reference field is 'field_uid_test', I tried using prepopulate to prepopulate the user reference field with user#3:
node/add/exampletype?edit[field_uid_test][0][uid]=3
But to no avail, the user reference field is still blank. If anyone has any hints or maybe a point in the right direction, I'd appreciate it. Thanks in advance!
--jBocalig
guys thanks a lot for the
guys thanks a lot for the info
i did it almost as Radiating Gnome told me, but i had to change the user reference to a node reference because views on uid always redirect me to the user profile page