adding a form to any page of the site that will submit to existing exposed view block

Events happening in the community are now at Drupal community events on www.drupal.org.
ben.hamelin's picture

I have a view, displayed as a block, with exposed filters, assigned to one page node on my site.
This is a simple search form with a Taxonomy drop down, keyword search for name, and a few other simple filters.

My problem is that I want to include an additional form on other pages of the site (a sidebar block for example) that will submit to this view.

Is this possible?

I'm testing now, but have yet to produce results.

I copied the HTML of the form and used that as my starting point.

Of course, this view uses AJAX as it has exposed filters and is output as a block.

Wondering if the setup will prohibit me from accomplishing this.

Any insight on this would be GREATLY appreciated!

Thanks!
bh

Comments

Use multiblock module is solve your problem

khuongkd's picture

Hi,
you can try using multiblock module: http://drupal.org/project/multiblock
I think it can help you.

workable solution using hook_views_pre_view

ben.hamelin's picture

Thanks khuongkd, I reviewed that module quickly but it didn't appear to do what I needed, specifically submit to an AJAX driven view output.

I found a workable solution, although I could see it being unwieldy for a view with many arguments.
In my case I only needed two, a taxonomy term id and a text string.

I was able to add two arguments to the block display. Order was important here, I ended up placing the tax id argument first as I could default that argument to "All" if there was no valid ID passed, where as the text string search (against a last name field, btw) either had to have a value or not be present. Passing in the blank string of course gave no results. I imagine I could handle that with some PHP validation within the argument settings of the view??

Ok, so, enter the hook_views_pre_view.
The hook takes three arguments : "_views_pre_view(&$view, &$display_id, &$args)"

We're interested in the last, the args array.

Within the hook I was able to detect the $_POST data, and manually update the args array. Here was where the order was important. By placing the TAX ID arg first in order within the view definition, it allowed me to always have a value to use for args[0], either the TAX id or all tax ids, separated by “+”.
This hung me up for a bit, as I initially was trying to use “All” as my default tax id, which is the value from the exposed filter, but after testing realized it was building the query using tax id “0”. Obviously this was returning no results.

Once the tax search was working, I added the last name argument to args[1] if it had been entered, otherwise I left args[1] unset.

This worked fine for me, although I feel like I've overlooked something.
I had trouble with the isolated cases for the arguments, in combination they worked great. Hence the ordering issue, and need to generate the default list of tax ids.

Does anyone have any other thoughts on this?

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: