Taxonomy DDS jump menu based on page

Last modified: December 8, 2007 - 14:27

The Taxonomy Drop Down Select Jump Menu page got me started in the direction I wanted to go for my site. I have modified the 5.x code to make it a bit more dynamic depending on the page I am viewing.

<?php
$output
= drupal_get_form('Category_dropdown_form', $form);
return
$output;

function
Category_dropdown_form() {
   
$vid=str_replace($GLOBALS['base_path'],'',request_uri());
    if (
drupal_get_normal_path($vid)) {
      
$vid=str_replace('taxonomy/term/','',drupal_get_normal_path($vid));
      
$term = taxonomy_get_term($vid);
      
$vid = $term->vid;
    }

    if (!
is_numeric ($vid)) {
      
$vid=8;
    }
   
$vName = taxonomy_get_vocabulary($vid);
   
$formname=$vName->name;
 
   
$vocabulary = db_query("SELECT td.name, td.tid FROM {term_data} td WHERE td.vid=%d ORDER BY td.name", $vid);
   
// Initialise the country array
   
$options[] = t('List of ' . $formname);
   
//Populate array with url / name
   
while ($term = db_fetch_object($vocabulary)) {
     
$tmpPath = drupal_get_path_alias('taxonomy/term/'.$term->tid);
     
$options[$GLOBALS['base_path'].$tmpPath] = $term->name;
    }
   
//Build dropdown select
    //If we try to build OnChange directly it gets mangled, so put in array to confuse the forms api
   
$form['category'] = array(
     
'#type' => 'select',
     
'#name' => $formname,
     
'#id' => $formname,
     
'#title' => '',
     
'#default_value' => '',
     
'#options' => $options,
     
'#description' => '',
     
'#multiple' => $multiple = FALSE,
     
'#required' => $required = FALSE,
     
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
    );
        return
$form;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.