Hi Guys

can someone explain to me how i can get a full list of users into a select form element please
i have managed to get my own name in but none others

TIA

Comments

adrianborrego’s picture

function _pruebas_form1() {
       
       $form [ 'user_select'] = array (
                '#title' => t ( 'Choose the user'),
                '#type' => 'select',
                '#options' => _getAllUsers(),
                '#description' => 'Choose the user',                
       );
      
       $form [ 'submit'] = array (
             '#type' => 'submit',
             '#value' => t ( 'submit'),
       );
       return $form;
}

/*
This function gets as all users in the database.
if you only want the active users then
$query = "select uid, name from users where uid > 0 and status = 1";
*/
function _getAllUsers() {

    $query = "select uid, name from users where uid > 0";
    $result = db_query($query);
    $users = array();
    while ($user = db_fetch_object($result)){
        $users[$user->uid] = $user->name;
    }
    return $users;
}

user_search() (API) can also be used but for me it is more difficult.

maori’s picture

Thankyou

worked like a charm :D