Using a select form field for the field that selects the groups where a node is posted The form for creating a node for the content type that has been set as content type for the Organic Groups module has checkboxes for choosing the groups where a node is posted; I want to use a select form field instead of the checkboxes.

How should I alter the form field?

I have tried some patches from drupal.org, but they do not works correctly. 

I have used the following code. 

/**
 * Helper function; Make the groups audience accept only a single group.
 */
function og_single_group_form_alter(&amp;$form, $form_state, $form_id) {
  if (module_exists('og_access')) {
    $path = drupal_get_path('module', 'og_single_group');
    drupal_add_js($path . '/og_single_group_hideoption.js');
  }

  if (!empty($form['og_nodeapi']['visible']['og_groups']) &amp;&amp; ($form['og_nodeapi']['visible']['og_groups']['#type'] != 'value')) {
    $options = array();
    $options = array(t('Personal blog')) + $form['og_nodeapi']['visible']['og_groups']['#options'];
    $form['og_nodeapi']['visible']['og_groups']['#type'] = 'select';
    $form['og_nodeapi']['visible']['og_groups']['#multiple'] = FALSE;
    $form['og_nodeapi']['visible']['og_groups']['#options'] = $options;
    // Add own submit handler so we can cast the groups back to an array.
    $form['#submit'][] = 'og_single_group_submit';
  }
}

 /**
  * Submit handler; Since we permit only a single group per content, we need to
  * case to groups into an array
  */
function og_single_group_submit($form, &amp;$form_state) {
   if (!empty($form_state['values']['og_groups']) &amp;&amp; !is_array($form_state['values']['og_groups'])) {
     $form_state['values']['og_groups'] = drupal_map_assoc((array)$form_state['values']['og_groups']);
   } 
  else if (empty($form_state['values']['og_groups'])) {
    $form_state['values']['og_groups'] = array();
  }
}


The code causes the following error: 


  Warning: array_filter() [function.array-filter]: The first argument should be an array in /var/www/mysite/sites/all/modules/contrib/og/og.module on line 1303.
I am replying basing on what you wrote in the comment to your question.

Organic Groups shows checkboxes or a select field basing on the number of groups that are listed in the "Audience" form field. If the number of groups is less than 20, the module will use checkboxes; otherwise, it will use a select box.

There is no way to change which form field is used, except using a module that alters the form fields added by Organic Groups. The following code, contained in og.module, is the code that adds the audience form field to the node edit form.

// show multi-select. if less than 20 choices, use checkboxes.
$type = $cnt &gt;= 20 || $is_optgroup ? 'select' : 'checkboxes';
$max_groups = variable_get('og_max_groups_'.$node-&gt;type,'');
$description_max_groups = ($max_groups &amp;&amp; !user_access('administer nodes')) ? format_plural($max_groups," Limited to !max_groups choice."," Limited to !max_groups choices.", array('!max_groups' =&gt; $max_groups)):'';
$form['og_nodeapi']['visible']['og_groups'] = array(
  '#type' =&gt; $type,
  '#title' =&gt; t('Audience'),
  '#attributes' =&gt; array('class' =&gt; 'og-audience'),
  '#options' =&gt; $type == 'checkboxes' ? array_map('filter_xss', $options) : $options,
  '#required' =&gt; $required,
  '#description' =&gt;  format_plural(count($options), 'Show this post in this group.', 'Show this post in these groups.') . $description_max_groups,
  '#default_value' =&gt; $groups ? $groups : array(),
  '#required' =&gt; $required,
  '#multiple' =&gt; TRUE);


It is enough to have a module that executes the following line, and the form field will always use a select box to show the list of groups to which associate a post.

$form['og_nodeapi']['visible']['og_groups']['#type'] = 'select';


The code needs to be executed inside the implementation of hook_form_alter(), or hook_form_FORM_ID_alter().