By Tpainton-1 on
I am having users create nodes that require their names, addresses, phone numbers etc.
One option is to simply use CCK and create these fields in the node that the user has to fill in. However this will very quickly become tedious for those users who want to submit multiple nodes and ar e forced to enter their information over and over..
What would be perfect is to place these fields in the user profile and then automatically import them into every node that user creates.
Thanks
Comments
Or..
I could convert my user profiles to nodes using nodeprofile and then the user fields would be cck fields.. I have tried looking at field thief and fieldreferene but both of these are not going to work..
Field thief requires knowing the nid of the node containing the field needed to be imported.. Something that is going to change because every user has a different nid for their nodeprofile.
Field Reference would work but my users are not going to undersand the selection tokens that come up in autocomplete and the reference list options..
If nodeprofile is used then the cck fields in the profile will have tokens so is there a way to automatically import field_fullname in the userprofile to field_username in the node created by the user?? Seems like it would be easy but I am having some trouble getting this sorted out.
Looking for a few hours I
Looking for a few hours I found this post. It seems to get me closer to pulling in user profile fields into default cck fields in a node created by the user..
http://drupal.org/node/186057
This code was posted..
I am trying to pull in a field from the user profile called profile_name so I modified the above code too.
But got this error..
The default value PHP code returned an incorrect value
Expected format :
array(
0 => array('value' => value for value),
// You'll usually want to stop here. Provide more values
// if you want your 'default value' to be multi-valued :
1 => array('value' => value for value),
2 => ...
);Returned value :
Am I close? All help would be greatly appreciated. Thanks.
perhaps my problem is that I
Okay... field is not populating.. I had some syntax error there as I did not include the category..Where exactly is the "category". Is that going to be the node title of the nodeprofile? In my case it's profile..
The corrected code I am trying and not working is..
Greatly appreciate help.. I think I am really close!!!!!
GOT IT.Okay for everyone
GOT IT.
Okay for everyone else out there working on this.. It's confusing because the initial set up is vague.
You don't need to use nodeprofile. Simply use Profile
First go to profile and create a new field and a new category. For instance Category = "Demographics" and Title "Full Name" make the form name profile_name.
Edit your profile and enter your name in the field ie Joe Blow.
Create a new content type such as Car
using CCK enter a new field for Car with label "owner", Name "owner", then click on default value and then the php code and enter the following code.
global $user;
$profile_data = profile_view_profile($user);
//"Demographics" is the Profile Category
//"profile_name" is the profile field name
$user_profile_data = $profile_data['Demographics']['profile_name']['value'];
$user_profile_array = array( array('value' => $user_profile_data) );
return $user_profile_array;
When you create content type car, the user's name should now autopopulate into the field "Owner".
Good grief. So simple and yet no simple guide for the php/drupal gut naive.
3am. Finally can go to sleep. Only took 6 hrs from first post to solve!! :)
Nice
I just wanted to tell you that you're awesome for posting this. No one was replying, but you still stuck it up there so that it would help someone else later. You truly are a champion of open-source logic, sir.
Cheers man!
Changes in Drupal 6
The profile module in Drupal 6 has changed.
Profile values now load directly into $user.
So:
global $user;
profile_view_profile($user); //execute function only, returns nothing.
Then you can refer to it like this:
$owner = $user->content['Demographics']['profile_name']['#value'] ;
return $owner;
Note the '#' in '#value' You can also get other information such as '#title'. See the code in API.
Another way if you just want the value with using profile categories:
global $user;
profile_load_profile($user); //execute function only, returns nothing.
Then you can refer to it like this:
$owner = $user->profile_name;
return $owner
Quentin Campbell