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

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 '13 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. – kiamlaluno Nov 20 '15 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.