By default select options i have left empty in admin of that content type.

I am trying to alter select list option of a content type using hook_form_alter.

I am setting the values to select values and is getting assigned.

Only issue is that its getting logged out with single refresh to create form of that content type form or try to submit that form. What am i doing wrong in the code.

Thanks in advance.

function hook_form_alter(&$form, &$form_state, $form_id)
    if($form_id == 'product_node_form')

            $users = db_select('users', 'u');
            $users->join('users_roles','ur','u.uid = ur.uid');
            $users = $users->execute()->fetchAll();

            $vendor_list = array("Tan" => "Tan");

            foreach($users as $key => $user)
                $vendor_list[$user->name] = $user->name;
            $form['field_publish_to']['und']['#options'] = $vendor_list;

1 Answer 1


Try to rename the variable $user/ $users. May be your code is overwriting the default $user object of drupal. Try after renaming the variables $user/ $users.

  • You have nailed it.That was the issue variable $users/$user was the real issue.
    – Ram
    Dec 3, 2013 at 10:20
  • If the OP showed all the code they are using, this should not be the case, since there isn't a GLOBAL $user; line.
    – apaderno
    Nov 20, 2015 at 20:15

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.