Create custom user filter in Drupal
For a little project I needed to list all users, but not with the default user information, but with extra profile_values. Since users were not known by username, but by user id, I wanted a filter for a quick search.
In my module I recreated the form:
function messageboard_form_alter($form_id, &$form) {
if ($form_id == 'user_filter_form') {
unset($form['filters']['status']['status']); // remove status filter
unset($form['filters']['status']['permission']); // remove permission filter
$form['filters']['filter'] = array (
'#type' => 'radios',
'#options' => array (
'role' => role, // keep role filter
'uid' => uid // add my uid filter
)
);
$form['filters']['status']['uid'] = array (
'#type' => 'textfield',
'#size' => 18,
);
}
)
At first I also had the code added to fill the user_overview_filter session array with the values of the added filter, but then I got a SQL error.
At the end I saw no other way then editing the user_filters() function in the user.module like this:
$sql = db_query("SELECT uid FROM {users}");
while($row = db_fetch_array($sql)) {
$options[$row['uid']] = $row['uid'];
}
$filters['uid'] = array('title' => t('number'),
'where' => 'u.uid = %d',
'options' => $options,
);
The options are necessary if you want the text of the search displayed correctly.
I would be nice if there was some kind of hook for editing these filters. If so, please let me know. I really don't like to edit core modules.



4 reponses to "Create custom user filter in Drupal"
1. Hi How did you create this
Hi
How did you create this one?
tnx.
Reall need this one.. Pls Help....
2. I was looking it.. thank you
I was looking it.. thank you so much
3. did you mange to this one
did you mange to this one
please let me know tnx
4. please tell me how to
please tell me how to customize forms like user registration, login, create blog entry
want to change all div tags in that forms