I have a module that when my user changes the user details hook_user onupdate, pushes these details to an external database. However I would like this to only work when role X is selected, else my module will not do anything. The role will not be in the users profile as this processing is happening before I update the users account.

Drupal 6 Thanks


 function checkrole_user($op, &$edit, &$account, $category = NULL){
 case 'submit':

  if ($edit['roles'] == 'Staff'){
  do xyz


Edit user form

  • Please don't change question in response to an answer. It's called chameleon question and it really really makes people dislike you and think twice if it's worth to answer you, if all they got is no upvotes, but a change in question that renders their answer irrelevant. You can always ask new, follow up question, linking to the previous one.
    – Mołot
    Commented Dec 20, 2013 at 11:57
  • I was just trying to keep it relevant, no major change made, apart from i removed a block of code that was not relevant to the question. Sorry
    – Tom
    Commented Dec 20, 2013 at 12:19

1 Answer 1


Use hook_user_presave() for any logic that you need to happen before user data is really updated, but also have access to new values:


$edit: The array of form values submitted by the user. Assign values to this array to save changes in the database.

$account: The user object on which the operation is performed. Values assigned in this object will not be saved in the database.

$category: The active category of user information being edited.

You need to test against $edit argument.

For Drupal 6, you need hook_user.

Act on user account actions.

Act when $op == 'submit', as:

submit: Modify the account before it gets saved.

Just as with Drupal 7, you must examine

$edit: The array of form values submitted by the user.

  • I totally forgot to say I am using Drupal 6 here
    – Tom
    Commented Dec 20, 2013 at 11:04
  • @Tom answer updated
    – Mołot
    Commented Dec 20, 2013 at 11:11
  • Thanks, that make sense I had used hook_user after update before to make the changes. I did adjust the code in my original question, is there a way to print contents of the $edit, I tried print_r (no luck). So that I can find what I need to be checking against in my if statement. Before I would use $edit['name']; to view the user name, but I am not sure what part of the array holds whether the role has been selected
    – Tom
    Commented Dec 20, 2013 at 11:47
  • @Tom to print contents of the $edit, install Devel module and use one of it's functions, for example dpm($edit).
    – Mołot
    Commented Dec 20, 2013 at 11:52
  • I am using the devel module now however am coming across issues with internal errors, when I use a second hook_user in the same module, please see [link] (drupal.stackexchange.com/questions/98050/…).
    – Tom
    Commented Dec 23, 2013 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.