Skip to content

Instantly share code, notes, and snippets.

@slivorezka
Last active August 29, 2015 14:23
Show Gist options
  • Save slivorezka/a794988818139ff36020 to your computer and use it in GitHub Desktop.
Save slivorezka/a794988818139ff36020 to your computer and use it in GitHub Desktop.
function demo_drupal_way_hierarchical_select_form_submit($form, $form_state) {
if ($form_state['triggering_element']['#name'] == 'submit') {
$term_names = array();
foreach ($form_state['values']['items'] as $tid) {
$term = taxonomy_term_load($tid);
if (isset($term->name)) {
$term_names[] = $term->name;
}
}
drupal_set_message(t('You entered the next location: @loc', array('@loc' => implode(', ', $term_names))));
}
}
function demo_drupal_way_hierarchical_select_form_submit($form, $form_state) {
if ($form_state['triggering_element']['#name'] == 'submit') {
$term_tids = array();
foreach ($form_state['values']['items'] as $tid) {
if (is_numeric($tid)) {
$term_tids[] = $tid;
}
}
// Select last value.
$last_chosen = end($term_tids);
// Redirect to term page.
if (!empty($last_chosen)) {
drupal_goto('taxonomy/term/' . $last_chosen);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment