Hello,

I have a view that filters are displayed.
I need to add url in my queries, the problem is that when I apply the filter queries added are deleted.

Example:

1: Url of view:
http://www.exemple.com/comparison
2: Url of sight with the filters:
http://www.exemple.com/comparison?tid_0=45&tid_All
3: Url of sight with queries added:
http://www.exemple.com/comparison?m0=15&m1=87&m2=31
4: Url of sight with filters and queries added (what I'd like to end):
http://www.exemple.com/comparison?tid_0=45&tid_All&m0=15&m1=87&m2=31

When I am in case 3 and that I change the filters in the order (apply), change my url for the Case 2. I now change my url for the Case 4.

Should I come to change the url filter (apply).

At line 970 views.module I:

// @todo deal with exposed sorts
  $form['submit'] = array(
    '#name' => '', // prevent from showing up in $_GET.
    '#type' => 'submit',
    '#value' => t('Apply'),
  );

But I can not find where is the url ...

Thank you in advance for your help!

Comments

merlinofchaos’s picture

Category: task » support
Status: Active » Postponed (maintainer needs more info)

So I presume the mX=XX pieces are how your extra stuff is being added? How does this work?

Clément’s picture

Yes, right.

My site shows models of motorcycles and would like to make a page to compare these models, like Honda Motorcycle except that the selection of models will be on the same page.

It does not seem that there is a module for this.

So I thought a page that contains the left block (views) to select models. In my main page it would display models based queries.

My view contains the field (name motorcycle) and the field CustomFields: PHP code
with it (to add requests to the url of each node):

<?php
$tab_query = array();
$tab_query['tid_0'] = !empty($_GET['tid_0']) ? $_GET['tid_0'] : 'All';
$tab_query['tid_1'] = !empty($_GET['tid_1']) ? $_GET['tid_1'] : 'All';

$nb_query_m = 0;
for ($i = 0; $i < 5; $i++)
{
	if (isset($_GET['m' . $i]))
	{
		$tab_query['m' . $i] = $_GET['m' . $i];
		$nb_query_m++;
	}
}
$tab_query['m' . $nb_query_m] = '';
print 
url($path = NULL, $options = array('absolute' => TRUE, 'alias' => TRUE, 'prefix' => 'comparison, 'query' => $tab_query ));
?>

( In my field "Name moto" the url: [phpcode][nid] )

My view works except that there are problems that famous query erased when using the filter.

Initially, to overcome the problem, I thought about using Ajax, but my PHP code field does not display the requests of the page when you change the values of the filter.

Thank you for your help!

merlinofchaos’s picture

I think what you need to do is add a hook_form_alter to add your fields to the exposed filter form so that they get retained when the form is submitted.

Clément’s picture

I try to look at this function but I do not understand how it works.
If I understand I must start works like this:

function views_form_alter{
??
}

Now I must add my queries to the form?

Thank you for your help!

dawehner’s picture

Status: Postponed (maintainer needs more info) » Active
<?php
function yourmodule_form_alter(&$form, &$form_state, $form_id( {
  if ($form_id == 'views_exposed_form') {
    $view = $form_state['view'];
    // etc.
  }
}
?>
Clément’s picture

Awesome it works!

Thank you very much for helping me!

I have two quick questions if I may (not very important):
1: I want this function works only when one is in sight "models" -> "block_2.

2: At the moment my job is on the page views.module. Is that his could be put into the template.php page? (Sorry if this is a stupid question ...).

My function now:

<?php
function views_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $view = $form_state['view'];
    if ($view->name == 'modeles')
    {
      for ($i = 0; $i < 4; $i++)
      {
        if (isset($_GET['m' . $i]))
        {
          $form['m' . $i] = array(
            '#type' => 'hidden',
            '#value' => $_GET['m' . $i],
          );
        }
      }
    }
  }
}
?>
dagmar’s picture

Status: Active » Fixed

No, you have to put this code in your own module.

You need a yourmodule.info file and yourmodule.module file,

put this code into yourmodule.module

function yourmodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $view = $form_state['view'];
    if ($view->name == 'modeles') {
      for ($i = 0; $i < 4; $i++)  {
        if (isset($_GET['m' . $i])) {
          $form['m' . $i] = array(
            '#type' => 'hidden',
            '#value' => $_GET['m' . $i],
          );
        }
      }
    }
  }
}

And if it helps, $view->name contains the name of the view being processed, and $view->current_display contains the display being processed.

dagmar’s picture

Status: Fixed » Active

woops

Clément’s picture

Status: Active » Fixed

Thank you very much, it's great!!

It remains for me to put the function in a new module but I do know is no problem.

Now the problem is solved! What a relief for me!

Status: Fixed » Closed (fixed)

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