Dependent Selects to feed on taxonomies I'm trying to create a module that generates a block with Dependent Selects to feed on taxonomies, I mean the first would be the term father Select first level and then display a Select with the children of that term and so on, this is the code that I have so far:


/**
     * Implements hook_block_view().
     */
    function bloque_busqueda_block_view($delta = '') {
        switch($delta) {
            case 'bloque_busqueda' :
                $block['subject'] = t('Criterio de busqueda');
                $block['content'] = bloque_busqueda_block_content();
                return $block;
                break;
        }
    }

function bloque_busqueda_block_content() {
    return drupal_get_form('ajax_dependent_dropdown');
}

function ajax_dependent_dropdown($form, &amp;$form_state) {
    $options_first = _ajax_get_first_options();
    $selected = isset($form_state['values']['dropdown_first']) ? $form_state['values']['dropdown_first'] : key($options_first);

    $form["dropdown_first"] = array('#type' =&gt; 'select', '#title' =&gt; 'Seccion', '#options' =&gt; $options_first, '#ajax' =&gt; array('callback' =&gt; 'ajax_dependent_dropdown_first_callback', 'wrapper' =&gt; 'dropdown-second-replace', ), );

    $form["dropdown_next"] = array('#type' =&gt; 'select', '#title' =&gt; $options_first[$selected] . ' ' . t('Subseccion'), '#prefix' =&gt; '



    ', '#suffix' => '
', '#options' => _ajax_get_next_options($selected), );

    $form["submit"] = array('#type' =&gt; 'submit', '#value' =&gt; t('Buscar'), );

    return $form;
}

function ajax_dependent_dropdown_first_callback($form, $form_state) {
    return $form["dropdown_next"];
}

/**
 * Retorna el tid de la taxonomía actual.
 */
function current_tid() {
    $term = taxonomy_term_load(arg(2));
    return $term -&gt; tid;
}

/**
 * Mide la profundidad de la taxonomía.
 */
function term_depth($tid) {
    $tid = db_query("SELECT tid FROM {taxonomy_term_hierarchy} WHERE parent = :parent", array(':parent' =&gt; $tid)) -&gt; fetchField();
    if ($tid == 0) {
        return 1;
    } else {
        return 1 + term_depth($tid);
    }
}

function _ajax_get_first_options() {
    $terms = taxonomy_get_children(current_tid());
    foreach ($terms as $term) {
        $options[$term -&gt; tid] = $term -&gt; name;
    }
    return $options;
}

function _ajax_get_next_options($key = '') {
    $options = array();
    $tid = arg(2);
    $tree = taxonomy_get_tree($vid = 2, $tid);

    foreach ($tree as $term) {
        if ($term -&gt; depth == 0) {
            $parent = $term -&gt; tid;
        } else {
            if ($term -&gt; depth &gt; 1) {
                $options[$parent][$term -&gt; tid] = str_repeat('-', $term -&gt; depth) . ' ' . $term -&gt; name;
            } else {
                $options[$parent][$term -&gt; tid] = $term -&gt; name;
            }
        }
    }

    if (isset($options[$key])) {
        return $options[$key];
    } else {
        return array();
    }

}




Thanks
you can use hierarchical_select module for this .