How to set form type as 'hierarchical_select' programatically?

by Gladiator   Last Updated October 20, 2017 20:07 PM

I am using the following code to create a form in Drupal 6. This code displays a drop down filter with which I can select the terms, and apply the filters using the GET method.

function sample_create_form () {
  $vid=2;
  $options = taxonomy_form($vid, $value = 0, $help = NULL, $name = 'sample');
  $form['#method'] = 'get';

  $form['option'] = array(
    '#type' => 'select',
    '#title' => t('Terms for the Website'),
    '#options' => $options,
    '#description' => t('Website category'),
  );

  $form['submit'] = array(
   '#type' => 'submit', 
   '#value' => t('Submit'),
  );

  return $form; 
}

I want to display the form as a Hierarchical Select type. I tried to use 'hierarchical_select' instead of 'select' in the above code but it didn't work.

Is there a way by which we can get the hierarchical select form?

I am using Drupal 6 and I have hierarchical select module enabled.

Any help highly appreciated.



Answers 2


I think its better to use hierarchical_select for element as it gives a FORM API that is really easy to use. Check the following snippet as reference

$form['hierarchical_select'] = array(
    '#type' => 'fieldset',
    '#prefix' => '<div id="hierarchical_select" class="hierarchical_select_wrapper">',
    '#suffix' => '</div>',
    '#attributes' => array(
        'class' => array('hierarchical-select'),
    ),
);
$form['hierarchical_select']['select_subject'] = array(
    '#type' => 'hierarchical_select',
    '#title' => t('Select the tag you wish to use.'),
    '#size' => 1,
    '#config' => array(
        'module' => 'hs_taxonomy',
        'params' => array(
            'vid' => 13 //The vocab id
        ),
        'save_lineage' => 1,
        'enforce_deepest' => 0,
        'entity_count' => 0,
        'require_entity' => 0,
        'resizable' => 1,
        'level_labels' => array(
            'status' => 1,
            'labels' => array(
                0 => t('Grade'),
                1 => t('Subject'),
                2 => t('Main Topic'),
                3 => t('Sub Topic'),
                4 => t('Standard'),
                5 => t('Sub-Standard'),
            ),
        ),
        'dropbox' => array(
            'status' => 0,
            'title' => t('All selections'),
            'limit' => 0,
            'reset_hs' => 1,
        ),
        'editability' => array(
            'status' => 0,
            'item_types' => array(),
        ),
        'animation_delay' => 400,
        'special_items' => array(),
       'render_flat_select' => 0,
       'path' => 'hierarchical_select_json',
    ),
    '#default_value' => 0,
);

I hope this helps.

Aneek Mukhopadhyay
Aneek Mukhopadhyay
January 04, 2013 18:03 PM

how do that in drupal 8' in a form

Gilberto Mangones
Gilberto Mangones
October 20, 2017 19:30 PM

Related Questions




Label for Child in Hierarchical Select

Updated March 07, 2017 00:07 AM


Hierarchical select module for drupal 8

Updated November 18, 2017 05:07 AM