As reported in hook_user() documentation:
$op What kind of action is being performed. Possible values (in alphabetical order):
- "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.
- "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.
- "validate": The user account is about to be modified. The module should validate its custom additions to the user object, registering errors as necessary.
The module needs to create its own database table in hook_install()
.
hook_user()
could be implemented with the following code, in example:
function perscriptions_user($op, &$edit, &$account, $category = NULL){
if ($op == 'register' || ($op == 'form' && $category = 'account')) {
$form['surgery_address'] = array (
'#type' => 'textarea',
'#title' => t('Surgery Address'),
'#required' => TRUE,
);
return $form;
}
if ($op == 'insert' || $op == 'update') {
prescriptions_save_user_profile($account->uid, $edit['surgery_address']);
}
if ($op == 'validate' && $category == 'account') {
// Verify the entered values are valid.
// In this example, the value is contained in $edit['surgery_address'].
}
}
prescriptions_save_user_profile()
is the function that saves the user profile values in the database. The code checks the category to avoid to show the same form fields in all the tabs shown in the user profile edit form.