hi -
i made a form_alter function to add a new select box that i didn't defined in views and i want to use its value after a small processing and pass it as the third argument of the view - here is the code i wrote - but somehow it works only the second time i click the exposed submit button. any suggestions?

<?php
function plimus_form_views_exposed_form_alter(&$form, &$form_state) {
  if ($form['#id'] == 'views-exposed-form-lounge-offers-page') {
    $categories = taxonomy_get_tree(4, 0, -1, 1);
    $tax[0] = 'all';
    foreach ($categories as $cat) {
      $tax[$cat->tid] = $cat->name;
    }
    $form['category'] = array(
      '#type' => 'select',
      '#title' => t('Category'),
      '#options' => $tax,
    );
    $category_tid = $form_state['view']->exposed_input['category'];
    $children = taxonomy_get_tree(4, $category_tid);
    $terms = array();
    foreach ($children as $term) {
      $terms[] = $term->tid;
    }
    $path = explode('/',$form['#action'],5);
    $path = array_slice($path,0,4);
    $form['#action'] = implode('/', $path) .'/all/'.implode('+', $terms);
  }
}

what i try to do here is to add an exposed filter of only the parent taxonomy term of selected nodes.
i know there is an issue that tries to deal with it by making a patch to the views module here - http://drupal.org/node/271833 , but my question tries to be more generic - is it possible and if so how to add a custom form element on hook_form_alter so i could pass a processed value to a predefined views argument?

thanks

Comments

merlinofchaos’s picture

This is a really clever try, and I salute you, but the reason it only works the second time is that the action is encoded into the form render, and that's what the browser uses. So the form renders without any exposed filters changed; your user changes one, but the original action is used, and while you created a new #action, it's too late for that to help.

What you need to do is a drupal_goto instead of rewriting the #action. That'll automatically redirect, but you have to be careful to *only* do the drupal_goto if you're not already on the right URL or you'll end up in a redirect loop.

domesticat’s picture

Status: Active » Closed (fixed)

Closed while closing all Views support requests with no activity for 6 months. If you still need help, you may re-open this issue at any time.