Is it possible to do this? I can't see any permission I can grant for roles. I want to let a user create other users, but only of a specific role.
2 Answers
I used this logic to get such a functionality in a project. and i hope it will be helpful to you.
function custom_module_name_perm(){
return array('create specific role user');
}
function custom_module_name_menu(){
$items = array();
$items['custom-user'] = array(
'title' => t('User Account'),
'page callback' => 'drupal_get_form',
'page arguments' => array('user_register_form'),
'access arguments' => array('create specific role user'),
'type' => MENU_CALLBACK
);
}
function user_register_form(){
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('Email Address'),
'#size' => 25,
'#required' => true,
'#weight' => 10,
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#size' => 25,
'#weight' => 20,
);
$form['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#size' => 25,
'#weight' => 30,
);
}
function user_register_form_submit(&$form, $form_state){
$values = $form_state['values'];
$save_user = user_save('', $values);
$load_user = user_load(array('mail' => $values['mail']));
$rid = <your role id>;
db_query("INSERT INTO {users_roles} (`uid`,`rid`) VALUES (%d, %d)", $load_user->uid, $rid);
}