Hi,
I have a front page with a views-exposed-form build with "Views".
I need to get 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 :

   //page front
   if($form['#id'] == 'views-exposed-form-front-page') {	
    $form['#action'] = '/accueil';//it change the URL on submit but I can't add the argument 

	//function to get the tid of the town taxon
        $commune = $form_state['input']['localite'];
	$taxonomy_id = taxonomy_get_term_by_name($commune);
	if(!empty($taxonomy_id)) {
		  $tid = -1;
		  foreach ($taxonomy_id as $taxonomy_item) {
			$tid = $taxonomy_item->tid;			
		  }
		}
	
	 if (empty($taxonomy_id)) {
        $tid='';
      } 
	
	//dpm($form);
	}

How can I rebuild the url now with the tid like this?
$form[argument]=$tid;

Comments

saurabh.dhariwal’s picture

Here's the work around.

function hook_form_alter(&$form, &$form_state, $form_id) {
        if($form_id == 'views-exposed-form-front-page') {
                $commune = $form_state['input']['localite'];
                $taxonomy_id = taxonomy_get_term_by_name($commune);
                
                $tid = 0;
                if(!empty($taxonomy_id)) {
                        foreach ($taxonomy_id as $taxonomy_item) {
                                $tid = $taxonomy_item->tid;                        
                          }
                }
                $form['#action'] = '/accueil?localite=' . $tid;
        }
}

Hope this helps you.

Thanks!

renatog’s picture

Assigned: Unassigned » renatog
renatog’s picture

Status: Active » Fixed

Hi guys.

Thank you very much @saurabhdhariwal. It's possible using form_alter

@zorax, You did it?

If have any question about it please comment for us.

Thank you very much.

Regards.

Status: Fixed » Closed (fixed)

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