0

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->fields('u',array('name')); $users->fields('ur',array('uid')); $users->condition('ur.rid',6,'='); $users->orderBy('u.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

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.

2
  • You have nailed it.That was the issue variable $users/$user was the real issue. Commented 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. Commented Nov 20, 2015 at 20:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.