Assigning a role in code isn't working I want to add a user to a role when a checkbox on the profile has been checked.
It's printing the dpm() message but not adding the user to the role. What am I missing.

function mycustom_form_user_profile_form_alter(&amp;$form, $form_state, $form_id) {
  $form['#validate'][] = '_user_profile_validate';
  ...
}



function _user_profile_validate(&amp;$form, &amp;$form_state) {
  if (($form_state['values']['field_restricted']['und'][0]['value']) == 1) {
    dpm('role added');
    global $user;
    user_multiple_role_edit(array($user-&gt;uid), 'add_role', 6);
  }
}
Your code seems fine. Maybe you could add an additional condition to see if your role argument is proper:

$role_name = 'Role to add'; // The name of the role to add.
  if ($role = user_role_load_by_name($role_name)) {
    user_multiple_role_edit(array($user-&gt;uid), 'add_role', $role-&gt;rid);
  }


I would try adding this condition to make sure all arguments are as intended. Maybe 6 is not a valid index? With this extra condition you will be sure.

Hope this helps, cheers!