Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
function MYMODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
// To grant access to all users
$form['account']['roles']['#access'] = TRUE;
// Convert checkbox to select list
$form['account']['roles']['#type'] = 'select';
// Remove administrator from options
foreach ($form['account']['roles']['#options'] as $key => $value) {
if($value == 'administrator') {
unset($form['account']['roles']['#options'][$key]);
}
}
}
Comments
Show User Roles in Registration Form
To show roles in registration form:
Yes Thats Right...
Yes thats right it worked for me, but my concern is about
Is there any alternative way ?
Use below code
Use below code to make it work:
Thanx a lot...
Finally below code worked for me...