Hi,
I have a front page with a views-exposed-form build with "Views".
I need to have from the user a town value (from a taxonomy) and then go to another view page (accueil) and change the value of the filter to get a number not a name value.

it works like this
on submit front page here is the url :
http://www.mysite.fr/front?localite=Sauve

And I need
http://www.mysite.fr/accueil?localite=12225
12225 is the nid of the town Sauve

I have build a module with hook form alter :

if($form['#id'] == 'views-exposed-form-accueil-page-1') {
$form['#action']='/accueil';//change the page of result OK
}

I have try to change the submit function with this :
$form['#submit'][]= 'justtosay_formtools_submit';

and add the submit function in my module

function justtosay_formtools_submit($form, &$form_state) {
...   
}

Is it tha way for changing the submission function and what function inside for looking in the taxonomy vocabulary, get the tid, and put in it in the url?
Thanks a lot.

Comments

valjr’s picture

Sorry if my comment here might be off-topic. I'm a newbie in drupal development and in this forum. I don't know yet where and how to post an issue in the forum. Hope the posters could understand. Thanks in advance.
Recently (to be precise, yesterday) I tried to add an item (field) in my view with a field collection relationship. To my surprise I cannot add the field. But before I was able to add fields from a filed collection view relationship.
I search with the same issue but this only happened years ago. I don't know what is the reason of this. Please help.

kshama_deshmukh’s picture

If I understood correctly, you want to get the term id from term name and pass into the URL so that your another view gets the term id.

You can pass the same value of a term name from front page view to another view page like - http://www.mysite.fr/accueil?localite=Sauve and then get the term id for that term name before actually passing the argument to another view of accueil.

This could be achieved using a hook_views_pre_view() hook in your custom module -

/**
 * Implements hook_views_pre_view().
 */
function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
  switch ($view->name) {
    case 'accueil' : // 'accueil' - replace this with actual view name used for http://www.mysite.fr/accueil?localite=
      // Get exposed filters value
      $filter_input = $view->get_exposed_input();
      $term_name = $filter_input['localite']; // 'localite' - replace this with actual exposed filter name
      // Get term id from term name
      $term_array = taxonomy_get_term_by_name($term_name);
      $term = reset($term_array);
      // Set exposed filter value to new one
      $view->exposed_input['localite'] = $term->tid; // 'localite' - replace this with actual exposed filter name 
      break;
  }
}
zorax’s picture

It works perfectly !
thanks a lot.
but the second view does'nt have the good url.
So If user select another categorie in the second view (accueil) to search in this town, the view is display without the localite filter..
(localite=All)

kshama_deshmukh’s picture

Setting the exposed filter value in hook_views_pre_view() should set your localite filter and even if user selects another category the view should show the set value of localite filter.

Have you done any settings for default value of localite filter in the view?