By BartVG on
Inspired by http://drupal.org/node/213069, I tried converting this code for use in D6. This is my result:
$view = views_get_view('frontpage2');
$form_state['view'] = $view;
$form_state['display'] = $view->display['default'];
$form = drupal_retrieve_form('views_exposed_form', $form_state);
$form['#action'] = url($view->display['page']->display_options['path']);
drupal_process_form('views_exposed_form', $form, $form_state);
return drupal_render_form('views_exposed_form', $form);
On the positive side: it works without breaking the site and it gives only 1 php warning.
On the negative side: only the submit button is showed. I think it has something to do with the $form_state array. I explicitly assign $view and $view->display['default'] to that array, but after that it seems to be the only content of it. I guess this array should come from previous form building stages? At least it should have more content than only the two variables that I assing to it. Does someone know where to get the rest of the array?
Comments
No progression
I'm also not sure whether the view object contains what it should contain:
Exposed inputs are not available (see views.module line 801 and includes/view.inc line 157 in views-6.x-2.0-rc1) when I call the view like this. The frustrating thing is that the exposed form does get rendered in the page view. :-(
Also, there are no filters in the object (see views.module line 816).
I'm giving up for now. Things get too complicated and I can't seem to find a solution. Ik word er stiepelzot van!!
Grrrr
I've just been struggling with the same problem - but I think I've cracked it!
Not been tested in anger, but it certainly seems to be working ...
Mike,
Computerminds offer Drupal development, consulting and training
Mike,
Computerminds offer Drupal development, consulting and training
Thanks a lot!!
Now it's working here too!
If you were a girl, I would ... euhm ... nevermind...
Works wonderfully,
Works wonderfully, thanks.
This is also at http://www.computerminds.co.uk/displaying-exposed-filter-form-views-drup...
set_display()
Posted at computerminds but just reposted here just in case someone's browsing.
I get this PHP error when I use the code above:
Fatal error: Call to a member function set_display() on a non-object in drupal\includes\common.inc(1547) : eval()'d code on line 4
What am I doing wrong? Using D6.6.
didn't change the your_view_name
Woops! If you encounter an error like mine, you forgot to change the view. LOL. This might need error checking then to prevent PHP compile errors. ^_^
Another thing, how do you stop the filters from showing up on the original place?
Not working with view display other than 'default'
Thanks for this code. It works great for the default display of a view but no matter what you put in the $view->set_display(); it still goes and looks up the default display.
Any tips?
Thanks!
_
You don't need to code this-- you can place the exposed filters in a block with the 'Exposed form in block' option in the Basic settings box.
Exposed filter block in panels does not seem to work
I am going to try this piece of code and report back to see if it works.
If I use exposed form block in a panel, it always returns the wrong url. I hope I can set it with this code.
Chris
http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.
Thank you!
WorldFallz, I know this is like a year late, lol ... but I just wanted to say thank you about this little tip -- it removes the need to use the php snippet at all!
"you can place the exposed filters in a block with the 'Exposed form in block' option in the Basic settings box."
_
lol, glad it was helpful ;-)
Thanks!
Worldfallz - thanks, that solved my issue immediately.
set exposed filter url and $view->set_display
I would like to pass in the url of the page the view is on.
exposed filters blocks do not work in a panel or a situation where you use node/%/foo as the url.
I am hoping that I could modify the code to ensure
1. that the url passed is the url of the given page
2. set $view->set_display() to take another value other than default
Any ideas?
http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.
I'd love to work through this
I'd love to work through this with anyone that's interested in starting a code scrum to figure it out.
Here's the magical thing!
Set the 'expose form in block' and voila, the form disappears from the page view!
(though it never appeared in the block view in the first place)
Also, I used the above code snippet in a custom block (PHP filter - and then did a "print $output" instead of the "return $output")
Thank you so much for this.
do it different way by accident
Hi ...I need both expose filter on it's own view's page (expose filter on on top of the results) and expose filter in a block when actually viewing the content. But after searching via this expose block, this expose block disappear.
By accident I was able to do this without using the snippets. Here's how I do it ...
1. Initially Exposed form in block: Yes. With this is, it create expose block, but REMOVE expose filter from view's page.
2. Enable the block from this expose block only on the pages detailed. (use block visibility but not on the view's page). Otherwise you'll have redundant filter (in the block and on top of the page)
3. Now, set .... Exposed form in block: No. Now, set it back into No so I can also have the filter on the view's page as well.
I have cleared cache & view's cache. Seems all working as I wanted. comment?
_
Sounds like a bug to me-- I don't know if I would rely on it as it might get fixed one day. But whatever works, lol.
I know this is an old post,
I know this is an old post, but it turned up in searches for this particular problem. There is a way of doing it without relying on the above behaviour though, although it's a bit clunky.
Basically, create your page view, set your filters, and expose them as required, but don't get it to produce a block. Then create an identical page view, with the same path, in the same collection of views (easy if your page is based on the default view), which has exposed filters in block turned on. It appears that views will then render the page from the first page view, and the block from the second, which, because it has the same path, will actually pass the filter values to the correct place.
In programming terms, it's a bit like overloading a function, although in this case, it's overloading an URL. Since the only difference between the two views is the exposed filter settings, there should be a minimal performance hit to it, although I'm not sure how having multiple pages with the same URL is handled.
Set Use AJAX
Also, I can solve this case setting Basic Settings/Use AJAX: Yes