You are here

function user_admin_role_validate in Drupal 7

Same name and namespace in other branches
  1. 5 modules/user/user.module \user_admin_role_validate()
  2. 6 modules/user/user.admin.inc \user_admin_role_validate()

Form validation handler for the user_admin_role() form.

1 string reference to 'user_admin_role_validate'
user_admin_roles in modules/user/user.admin.inc
Form to re-order roles or add a new one.

File

modules/user/user.admin.inc, line 991
Admin page callback file for the user module.

Code

function user_admin_role_validate($form, &$form_state) {
  if (!empty($form_state['values']['name'])) {
    if ($form_state['values']['op'] == t('Save role')) {
      $role = user_role_load_by_name($form_state['values']['name']);
      if ($role && $role->rid != $form_state['values']['rid']) {
        form_set_error('name', t('The role name %name already exists. Choose another role name.', array(
          '%name' => $form_state['values']['name'],
        )));
      }
    }
    elseif ($form_state['values']['op'] == t('Add role')) {
      if (user_role_load_by_name($form_state['values']['name'])) {
        form_set_error('name', t('The role name %name already exists. Choose another role name.', array(
          '%name' => $form_state['values']['name'],
        )));
      }
    }
  }
  else {
    form_set_error('name', t('You must specify a valid role name.'));
  }
}