Community

Passing arguments to CCK from user profile page

It's taken me a while to figure this one out so I thought I'd share this with the community since there is not much documentation on this.

If you would like to pass argument to CCK, such that those arguments are used to populate fields here is how:

From a user's profile page you should have a link such as:

<a href="/node/add/user-action/<?php $id = arg(1); $profileuser = user_load($id); print $profileuser->uid;?>">Add User Action</a>

here I am adding a content type of user-action, from the user's page. This will add the user's user-id to the URL so that it can be passed to CCK.

Then, within your content-type, you need to a field of type "user-reference". For that field, you will need the following default value:

$id2 = arg(3);
$profileuser2 = user_load($id2);
return array(0 => array ('uid' => $profileuser2->uid));

This takes the third argument in the URL, which is the user-id, and returns that user's value to the field.

That's it!

The only think i still haven't figured out, is how to force the default value and make this cck field un-editable by the user but not by the default.

nobody click here