Drupal 6: custom profile fields and storing data in the database

So, I added a few separate profile fields (admin -> profiles), which are all great, but completely useless if I can't store the information in the database. I've searched for hours trying to find a "best practice" way to do this, very little luck.

Should I add new columns to the Users table? Create a new table? I even found a vague link that the main profile module was supposed to add these columns for me anyway? And that you should be able to use CCK in the main profile module (but I don't have any options for that)?

And then I obviously want to allow the user to update their own fields, but the custom profile fields are not included in the $ form array ...

PS arrrggg! Drupal is leading me around the bend with its inconsistency and has to crack it all the time!

+2


source to share


1 answer


If you are using the main profile module, the database storage is provided automatically and you do not need to change anything in the database. When installed, the module adds two tables to the database profile_fields

for storing your custom field definitions and profile_values

for storing user-supplied data for those fields.

Fields are automatically added to user edit forms via implementation hook_user

in profile_user()

- the same mechanism is used to add the values ​​of these fields to a custom object on load.



So if these fields are not showing up for you, something fishy - have you added your fields to "categories"? If so, they will not appear on the standard user edit page, but on additional new pages (one category at a time). They are added as a type of menu MENU_LOCAL_TASK

, so they have to create new "tab" entries at the top of the user edit page - maybe you have a theme that doesn't display tabs?
Another thing to check is the field visibility settings selected in the field configuration form. If this parameter is set to "hidden", the field is only available for administrators and module / theme code. You should at least set it to 'private' if the user has to edit it himself.

Regarding the use of CCK fields, I don't think it is possible in the main profile module (maybe this could be provided by some extension module). Another approach is used by the Content Profile Module . It creates a custom node type for custom profiles so that the profile values ​​are stored as standard Drupal nodes. One of the advantages of this is that you can use all CCK fields for profiles, since you just need to add them to the generated node type.

+4


source







All Articles