For adding multiple members to a group (course in opigno), I implemented the chosen module for better UX on the select options but instead of displaying usernames I want to display realnames.

Using $account-realname in the user loading loop displays them but after submission it breaks, as I think it expects to receive name instead.

$form['massadd']['#options'][$account->uid] = $account->realname

$gid = current($form['group_ids']['#value']); 
$node = node_load($gid);

$form['massadd'] = array(
'#type' => 'select',
'#title' => t('Select students to add to the group'),
'#required' => TRUE,
'#multiple' => TRUE,

$users = entity_load('user');
 foreach ($users as $uid => $account) {
  if ($uid && !in_array($uid, $exclude)) {
    $form['massadd']['#options'][$account->uid] = $account->name; // tried realname instead


 $form['submit']['#weight'] = 0;
  // We validate our own way.
  $form['#submit'][] = 'opigno_simple_ui_form_og_massadd_massadd_form_add_roles';
  $form['#submit'][] = 'opigno_simple_ui_form_og_massadd_massadd_form_add_state';
  $form['#submit'] = array_merge(array('opigno_simple_ui_form_og_massadd_massadd_form_prepare'), $form['#submit']);
  • Would this possibly require to change content before form submission (name instead of realname for each selection) or any way to manipulate what's being displayed vs used?
    – Markus
    Jun 14, 2018 at 15:50

1 Answer 1


Having changed it to $account->name I managed to find out what's going using devel command dpr($variable) which contained the users uid.

Then I just needed to replace the user lookup query accordingly to cross check from realname table with that of the users based on uid.

$query = db_select('realname','rn');
$query->fields('rn', array('uid'));
$result =$query->execute()->fetchAll();

if (!empty($result)) {
$uids =array($result[0]->uid);
$account = user_load_multiple($uids);
$account = array_shift($account);

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.