How can I hidden with alter_form to hide the user_filter_form in the page of list of users to a specific role?

1 Answer 1


hook_form_alter() wouldn't actually be the best place for this; the form is actually called in from user_admin() so the best place for your code would be hook_page_alter().

The first thing you should do is create a custom permission that you can assign to the role:

function MYMODULE_permission() {
  return array(
    'access user filter form' =>  array(
      'title' => t('Access User Filter Form')

Then implement hook_page_alter() to hide the form:

function MYMODULE_page_alter(&$page) {
  // Make sure this is the right page
  if (arg(0) == 'admin' && arg(1) == 'people') {
    // Make sure filter form actually exists
    if (isset($page['content']['system_main']['user_filter_form'])) {
      // Check user access
      if (!user_access('access user filter form')) {
        // Deny access to the form if necessary
        $page['content']['system_main']['user_filter_form']['#access'] = FALSE;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.