I have a problem in a multi-part form I'm building as part of the admin page for a module I'm developing.

I pull an array from a DB table, but I can't render the form radio buttons using the array. Everything displays right, I get no errors, but no radios appear (the title and description display fine) and I know the array is populated by the message.
code:

$listo = array();
	$result = db_query('SELECT * FROM {gallerease} n WHERE n.master = 1');
	while ($list = db_fetch_object($result)) {
		array_push($listo, $list->tags);
	}
	$listn = array_unique($listo);

	$form['taglist'] = array(
	    '#type' => 'radios',
	    '#title' => t('Image galleries'),
	    '#options' => $listn,
	    '#description' => t('Select a tag to edit associated images'),
	);
	$form['submit'] = array(
		'#type' => 'submit', 
		'#value' => t('Submit') 
	);
	drupal_set_message(count($listn) . $listn[0]);
	$output = '';
	$output .= drupal_render($form['taglist']);
	$output .= drupal_render($form['submit']);
	return $output;	

Comments

jefflane’s picture

What happens when you populate your options manually? Do any radios appear?

Replace '#options' => $listn,

With
'#options' => array( t('option 1'), t('option 2'), t('option 3') ),

To debug

tkilbour’s picture

Hmm, manual options don't work either. When I change the form type to 'select' they show up fine, but I get this error: warning: implode() [function.implode]: Invalid arguments passed in /home/****************/public_html/includes/form.inc on line 623. Then the rest of the form becomes unusable, obviously. I wonder if it's the same problem, but drupal isn't catching an error message for the radios?

However! If I change the form handling around so that the menu item callback is drupal_get_form(), with the form function as a callback argument, then return $form in the form function everything works fine. But I really don't want to do it that way because I need to display a bunch of other stuff on the page besides just a form.

Here is all the code I'm using:

function somename_menu() {
  $items = array();
    $items[] = array('path' => 'admin/settings/somename',
      'title' => t('somename Tags'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('somename_select_tag_form'),
      'description' => t('Manage galleries'),
      //'callback' => 'somename_select_tag_form', // when I use this method I get the errors described above
      'access' => user_access('administer site configuration'),
      'type' => MENU_NORMAL_ITEM);
  return $items;
}

function somename_select_tag_form() {
		
	$form = array();
	$form['#multistep'] = TRUE;
	$form['#redirect'] = FALSE;

  if ($form_values === NULL) {
	$listo = array();
	$result = db_query('SELECT * FROM {somename} n WHERE n.master = 1');
	while ($list = db_fetch_object($result)) {
		array_push($listo, $list->tags);
	}
	$listn = array_unique($listo);

	$form['taglist'] = array(
	    '#type' => 'select',
	    '#title' => t('Image galleries'),
	    '#options' => $listn,
	    '#description' => t('Select a tag to edit associated images'),
	);
	
	$form['submit'] = array(
		'#type' => 'submit', 
		'#value' => t('Submit') 
	);
	drupal_set_message(count($listn) . $listn[0]);
	
	/* using this to render the form causes the error
	$output = '';
	$output .= drupal_render($form['taglist']);
	$output .= drupal_render($form['submit']);
	*/
	
  }
  
  else {
	$val = $_POST['taglist'];
	$val = $listn[$val];
	
	$output = $val;
	}
	return $form;
}