I'm not even sure this is possible, but I'd like to use the form_alter hook to add fields to the core user form. I've done this and the fields and fieldset display just fine. I'm doing this to add custom information, but my problem is figuring out how to have this information saved to a table unique to the module -- ie: I don't want to hand edit / hack the drupal user.module to include my fields. I naively tried the hook_insert, and well, that didn't work. Anyway, is this possible? If so, can someone point me in the right direction?

Comments

styro’s picture

I would've thought hook_user would've been the best approach (not that I know for sure)...

http://api.drupal.org/api/function/hook_user/5

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

kxerc’s picture

Thanks much Styro. Yeah, that is a better approach, but it is still not clear to me how data from my custom fields could get saved to another table -- its not clear how I can insert a secondary insert / update / delete hook. From the example provided, it looks as if the data would just dump to 'data' field in the user table, which appears to be a random string.

cwgordon7’s picture

If you had actually read the link you were given, you would have seen:

"update": The user account is being changed. The module should save its custom additions to the user object into the database and set the saved fields to NULL in $edit.

"insert": The user account is being added. The module should save its custom additions to the user object into the database and set the saved fields to NULL in $edit.

So, what you need to do is invoke hook_user() when $op == 'update' and $op == 'insert'. Then you save your custom additions to the user object into your own database table. The user table does not accommodate random fields from contributed modules. So, use hook_install to create your database table, probably with the columns "uid" and "mymodulesfield". Then, simply save it to the database, and set the field in $edit to NULL. Retrieve it from the database when $op == 'load'.
---
If you have any trouble creating, configuring, or adding features to your Drupal website, I can help!
You can contact me through my personal contact form.