tags:

views:

2232

answers:

2

So i've added several some custom profile fields (administer -> profiles) which is all fine but completely useless if I can't store the information in a database. I've been searching for hours now trying to figure out the "best practices" way for doing this with very little luck.

Do I add the new columns to the Users table? Do I create a whole new table? I even found a vague reference that the core profile module should have added those columns for me anyway? And that you should be able to use CCK in the core profile module (but I don't have any options for that)?

And then I would obviously want to allow user to update their own fields but the the custom profile fields aren't included in the $form array...

PS arrrggg! Drupal is driving me around the bend with its inconsistencies and having to hack it all the time!

+4  A: 

If you use the core profile module, the database storage is provided automatically and you will not need to modify anything in the database. On install, the module adds two tables to the database, profile_fields to store your custom field definitions and profile_values to store the user supplied data for those fields.

The fields are automatically added to the user edit forms, via the hook_user implementation in profile_user() - the same mechanism is used to add the values of those fields to the user object when that gets loaded.

So if those fields don't show up for you, something is fishy - have you added your fields with 'categories'? If so, they won't show on the standard user edit page, but on additional new pages (one per category). These are added as menu type MENU_LOCAL_TASK, so they should create new 'tab' entries at the top of the user edit page - maybe you have a theme that does not display the tabs?
Another thing to check would be the fields visibility settings chosen on the fields configuration form. If that is set to 'hidden', the field is only accessible for administrators and module/theme code. You should at least set it to 'private' if the user is supposed to edit it himself.

As for using CCK fields, I don't think that this is possible with the core profile module (maybe some extension module provides this). A different approach is taken by the Content Profile Module. It creates a custom node type for user profiles so that the profile values are stored as standard Drupal nodes. One advantage of this is that you can use all CCK fields for profiles, as you just need to add those to the created node type.

Henrik Opel
There is a profile_fields table (stores all the fields) and a profile_values table (which matches the field id to the user id)... oh... hang on... 1 second... I see... it's not retroactive! Those fields only get attached to a new registered user and not the old ones! So stupid, now I've got to remember to add the new fields to each existing user everytime in the table. Do you know if there's option to make sure these fields get applies to existing users?
EddyR
As for the table name - yup, it's `profile_values`, not `profile_schema`. Will edit to fix this. Concerning 'it's not retroactive' I'm not sure what you mean exactly. Testing this locally, the categories/fields show up on the user edit pages for all users immediately - but there will only be an entry in the `profile_values` table if the user actually filled out a field (In other words, Drupal will not create an 'empty' entry there upfront).
Henrik Opel
A: 

I have the same question as EddyR...so there is no option to make sure new fields get applied to existing users? I added a new Yes/No checkbox option for users to receive email updates in their profiles. This is defaulted to 'Yes'....However, I noticed that only if I manually go into each user's profile via the gui and click 'Save' does this option goes into effect. I can't seem to find the option to set 'Yes' for each user in the database. Where do I look? I looked at the profile_fields and profile_values tables, but I don't see how those are related to the users directly.

Tiffany