0

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.

0

1 Answer 1

3

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.

4
  • This is what I was looking for:) Thanks a lot aneek :)
    – Gladiator
    Commented Jan 5, 2013 at 5:54
  • I've tried to use this code in hierarchical_select-7.x-3.x but is doesnt quite work. There are several deprecated function from hs 2.x to 3.x. is there an updated example of this code available?
    – John R
    Commented Nov 20, 2015 at 13:48
  • @JohnR this might happen. This was with a old module. The module itself has an api.php and readme. Have you had a look at those? Commented Nov 22, 2015 at 6:39
  • Yes, I've been fumbling through it for a few days now... I was using the readme, this post, Wim Leer's HS repo and this link to try and update. I'm making progress very slowly... but i could certainly use some pointers.
    – John R
    Commented Nov 23, 2015 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.