function apply_for_role_form_alter in Apply for role 7.2
Same name and namespace in other branches
- 7 apply_for_role.module \apply_for_role_form_alter()
Implements hook_form_alter().
File
- ./
apply_for_role.module, line 373 - Allows users to apply for roles.
Code
function apply_for_role_form_alter(&$form, &$form_state, $form_id) {
if (!($form_id == 'user_register_form')) {
return;
}
// Admin created account aren't processed by the module.
if (user_access('administer users')) {
return;
}
elseif (variable_get('apply_for_role_register', 0)) {
$filter_roles = array();
foreach (variable_get('users_apply_roles', array()) as $rid => $role) {
if ($rid > 2) {
$filter_roles[$rid] = $role;
}
}
if (count($filter_roles)) {
$form['apply_for_role'] = array(
'#type' => 'fieldset',
'#title' => t('Apply for role'),
'#collapsible' => FALSE,
);
if (variable_get('apply_for_role_multiple', 0) == 0 && variable_get('apply_for_role_register', 0) == 1) {
$filter_roles[0] = t('--');
ksort($filter_roles);
}
$form['apply_for_role']['rid'] = array(
'#type' => variable_get('apply_for_role_multiple', 0) ? 'checkboxes' : 'select',
'#title' => variable_get('apply_for_role_multiple', 0) ? t('Select a role or roles') : t('Select a role'),
'#options' => $filter_roles,
'#required' => variable_get('apply_for_role_register', 0) == 2 ? TRUE : FALSE,
);
if (count($filter_roles) >= 1 && variable_get('apply_for_role_register', 0) == TRUE) {
$form['apply_for_role']['rid']['#default_value'] = key($filter_roles);
}
if (variable_get('apply_for_role_allow_message', 0)) {
$form['apply_for_role']['apply_for_role_message'] = array(
'#type' => 'textarea',
'#title' => t('Application details'),
'#description' => t('Enter an explanation for how you will use the role, if it is granted.'),
);
}
}
}
}