Posted by abel_osorio on November 14, 2012 at 12:39pm
Hi, i have to embed multiple views on an page. The code of page is:
<?php
function form_consulta_cupo_libre($form, &$form_state) {
$form = array();
$peso = 0;
$views = array('consulta_cupo_libre', 'consulta_cupo_libre_total_cereal');
foreach ($views as $view) {
$view_object = views_get_view($view);
if (!is_object($view_object)) continue;
$peso++;
$form["formulario_$peso"] = search_form_element('fieldset', array(
'#title' => $view_object->get_title(),
'#weight' => $peso
));
$form["formulario_$peso"]['view'] = array(
'#markup' => $view_object->preview(),
'#weight' => $peso
);
unset($view_object);
}
return $form;
}
?>Each view is contained in a fieldset.
With this there not problem. The problem is that all the Views must share the same filters, and i don't know how do it.
Any suggestion?
Thanks in advance.
Comments
try using a block
First - make sure the filters in each view share the same name for the same filter, e.g. field_name filter is 'name' and field_other is 'otherfield' on each. Verify if needed by creating a page view for each an inspecting the query string (part of the url after ? you should see name=foo&otherfield=bar for each in this case).
Next, set one of the views to expose it's form in a block and add that block to that page.
Then in a custom module alter the exposed form -
mymodule_form_views_exposed_form_alter(&$form, $form_state) {
$path = request_path(); // 7 - For Drupal 6, one has to use $_GET['q'].
$form['#action'] = $path;
}
This should make the block submit to the current page. Exposed filters should check the url for the variables.
Haven't tested so may need tweaking but the idea is sound.
also see: http://drupal.org/node/364859
btw- I've run into needing this a few times and each time have to recall the steps through trial and error, so if you get it to work reply back with steps, or even better, add it to the tips/tricks or submit for addition to docs - see http://drupal.org/node/431846
I'm unique, just like everybody else.
If I helped, please pay it forward, backward or sidelong.