So i love the Hierarchical Select module and it answers a lot of my needs but... i cant get the results onto the page i have put the following code:-

case 10:
array_push($worked, l($item->name, "taxonomy/term/" . $item->tid));
break;
}

into my template and then echoed it out like this:-
<?php print implode(" ", $worked);?>

this didn't work despite the fact i followed the same model as for my other Categories.

am i missing something here?

many thanks for a great module Wim.

CommentFileSizeAuthor
#7 screenshot.jpg13.41 KBmouse77e

Comments

wim leers’s picture

Are you using the $worked array for the #options property? Please post a more complete code sample.

mouse77e’s picture

I'll post a fuller code sample later when i get back to my machine.
many thanks for the reply but out of interest how do you do it?

wim leers’s picture

See API.txt, the "Form API usage" section.

wim leers’s picture

Status: Active » Postponed (maintainer needs more info)
mouse77e’s picture

So... if my category is called "WORKED" i would copy this amended code into my page template?

  $form['select_some_term'] = array(
    '#type' => 'hierarchical_select',
    '#title' => t('WORKED.'),
    '#options' => $options, // Contains an array of tid - term name pairs.
    '#hierarchical_select_settings' => array(
      'module' => 'taxonomy',
      'save_lineage' => FALSE,
      'enforce_deepest' => FALSE,
      'level_labels' => array(
        0 => t('Main category'),
        1 => t('Subcategory'),
      ),
      'params' => array(
        'vid' => $vid,
      ),
      'animation_delay' => 400,
      'dropbox_title' => t('These are the terms you selected'). ':',
    ),
    '#default_value' => '83',
  );

Then Echo it out?

Sorry Wim, i suffer from Dyslexia and whilst this module is a god send, this is not 100% clear for me...

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Postponed (maintainer needs more info) » Fixed

It seems to me you don't know how to use the Forms API yet? If I'm right, please read the Quickstart Guide.

As an example (extracted from the code used here):

function vocabulary_to_options($vid) {
  $tree = taxonomy_get_tree($vid);
  if ($tree) {
      foreach ($tree as $term) {
        $choice = new stdClass();
        $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
        $options[] = $choice;
    }
  }
  return $options;
}

function yourmodule_some_form() {

  $form['categories']['third'] = array(
    '#title' => 'hierarchical_select demo (taxonomy module) vocabulary 3',
    '#description' => t('And yes, selecting a location can now be done very easily, by simply creating the correct vocabulary!'),
    '#required' => FALSE,
    '#default_value' => 45,
    '#type' => 'hierarchical_select',
    '#options' => vocabulary_to_options(6),
    '#hierarchical_select_settings' => array(
      'module' => 'taxonomy',
      'params' => array(
        'vid' => 6,
      ),
    ),
  );

  return $form;
}
print drupal_get_form('hierarchical_select_demo_form');
mouse77e’s picture

StatusFileSize
new13.41 KB

Wim, many thanks.
i fear that we are at misunderstanding each other. getting the form to display has been, thanks to your wonderful module, been very easy. my issue is how to get the Results from the form onto the finished users page.

as you can see from the screenshot the form works very well indeed! but as you correctly worked out i am a n00bie with Drupal.

any help is VERY greatfully received.

wim leers’s picture

You will want to write a FAPI submit handler to save the options the user selected. See http://api.drupal.org/?q=api/file/developer/topics/forms_api.html/5 and scroll down to "Submitting Forms".

mouse77e’s picture

I think i mentioned in another post i am dyslexic... having asked Wim my question on displaying the selected multiple choices from the category i realized i had boobed.

i had ommited to add the line $location = array();

// Split the taxonomy up into one variable per vocabulary
$communities = array();
$hobbies = array();
$reading = array();
$music = array();
$video = array();
$location = array();

foreach ((array)$node->taxonomy as $item) {
  switch ($item->vid) {
    case 1:
      array_push($communities, l($item->name, "taxonomy/term/" . $item->tid));
      break;
    case 2:
      array_push($hobbies, l($item->name, "taxonomy/term/" . $item->tid));
      break;
    case 3:
      array_push($reading, l($item->name, "taxonomy/term/" . $item->tid));
      break;
    case 4:
      array_push($music, l($item->name, "taxonomy/term/" . $item->tid));
      break;
    case 5:
      array_push($video, l($item->name, "taxonomy/term/" . $item->tid));
      break;
    case 10:
	  array_push($location, l($item->name, "taxonomy/term/" . $item->tid));
      break;
    }
}

Wim, my apologies!

wim leers’s picture

No worries :)

Also: a shorter equivalent of array_push($video, $item) is: $video[] = $item.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

afagioli’s picture

Hi
The #6 example was very helpful to me.
It may be a good idea to add the vocabulary_to_options() in the API.txt?

thanks a lot!

wim leers’s picture

I'll probably start working on the next major version of HS in about a week. That version won't degrade to a normal JS (which means that the HS widget will look virtually identical when JS is disabled), and thus #options will become completely obsolete. So for now, I'll refer people to this issue.

Glad it helped you :)