It's great to have exposed filters to search the view. But, sometimes they are too wide. This sample code shows how to change the search filter display.
In this case, I've changed the width of filter fields and the submit button label.
Put the following code in the end of your theme's template.php file:
/* Change the width of filter fields and the label of the submit button on the 'board' form */
function phptemplate_views_filters($form) {
if ($form['#view_name'] == 'board') {
$form['filter2']['#size']=15;
$form['filter3']['#size']=15;
$form['submit']['#value']='חפש';
}
return theme_views_filters ($form);
}
To change your own fields, simply enable the 'devel' module, print the form values with dprint_r($form)
, find the values you'd like to change, and change them. Then call the regular callback function to do the rest of the stuff for you.
Enjoy!
Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting | Eco-Healing | Effective Hosting Strategies | בניית אתרים
Personal: Hitech Dolphin: Regain Simple Joy :)
Comments
But for those who don't know php...
...could you please give complete instructions? I can't get what should I do after editing template.php and installing devel module. What does "print the form values with dprint_r($form)" exactly mean? Could you give an example?
Thanks
This was just what I was looking for
Amnon, great work!
airali, the example has all of the code you need to change the size of a text box in an exposed view.
Find out the name of your view in Admin -> Site Building -> Views and use that where Amnon uses 'board' (keep the quotation marks).
Instead of using the devel module, you can also find out the name of the form element you want to change by loading your view and looking at the source HTML. Your text field will be named filter0, filter1, filter2, etc, or something.
What is that 3 letter word
Note, the original snippet has hebrew appearing on the submit button, change the 3 letter word to Search or submit, or whatever you need it to say.
I am trying to change the
I am trying to change the size of my exposed views filters. I am using drupal 7. Using the code provided I am not sure what to change.
1. Do i replace filter0 with the "filter identifier"/"name=""" required by views or the label name?
2. I am exposing the filter in a views block. Do I use the name of the views-block or the name of the views-page?
Using firebug to expose my html I see tags for:
form id:
I am trying to change size from 60 to 18. I am unable to access the div class.
Complete overhaul of layout
This takes the form out of the table and renders it more like a normal Drupal form.
This goes in template.php:
--
How to override HTML in Drupal 6
how to not display results by default?
this works great.
how to display just the search form and NOT showing the results by default?
It looks like the default selection in the filter fields is set to ...
The default state of the
The default state of the filters can be configured within the View's settings, although you may have trouble getting the list to be completely empty. You could get more flexibility by loading the filter into a custom block with the following code.
You'll have to use CSS if you want to hide the original filter form.
Source: http://www.angrydonuts.com/displaying_views_exposed_filters#comment-2424
--
How to override HTML in Drupal 6
How can i achieve this using drupal 6?
How can i achieve this using drupal 6?
I have a view then by default my view displays the fields.
I would like only the filter form being displayed at first,
then display the fields only if user used the filter form.
fyi:
fyi: http://drupal.org/node/262270
--
Neil Cameron
tpl.php style
Per the above, what's working for me is doing my exposed filters in a tpl.php file. This is good for complete customization of the exposed filters form, and since it's all HTML, it's good for those who don't know PHP.
For my solution, I've got the 'Exposed form in block' option set to Yes in view settings, and I have the block set to appear only on the front page. So, I copied the HTML for the filters form from View Source into a file called block-views--exp-myviewname-displayname.tpl.php and started rearranging/prettifying the form however I wanted it.
salud...
Love this solutions! Works
Love this solutions! Works perfect, all customized.
need more explanation
do you have example or can you explain in more detail?
thanks!
The same thing in Drupal 4.7
If anyones trying to theme their exposed filters in the old Drupal 4.7, I've adapted Rowanw's code as per below:
Cheers.
Doesn't seem to work in Drupal 6
Hi, I tried this in Drupal 6, but there is no key named "#view_name." There's just "#id." I tried using that in template.php but nothing happens at all. Any ideas?
My code looks like this:
Hi, In Drupal 6 you should
Hi,
In Drupal 6 you should use hook_preprocess_views_exposed_form instead, here's a quick example:
More can be found here: http://drupal.org/node/320992#comment-1732960
Tom
______________________________________________
https://tomswebstuff.com
Note for the newbie
If your field name looks like filter1[city] (put anything in place of "city"), you'll need to call it like this:
$form['filter0']['city']['#size']= 30;
dprint_r($form) can be put at the end of the same function in template.php like this:
function phptemplate_views_filters($form) {
dprint_r($form);
return theme_views_filters ($form);
}
putting it into the page.tal.php in any other way didn't work for me.
I keep getting a call to
I keep getting a call to undefined function when I use this
So how do you print_r the array for an exposed views filter
Devel module
bjraines
The Devel module must be enabled to use the dprint() function.
Dave
Change number of options in select box
I am trying to change the number of items visible in a multiselect box. It is longer than the ones next to it, and I want to limit it to 5 items and have it scroll. This is set by
... I cannot, for the life of me figure out how to target that stupid select box. I got the submit button text changed fine:
And while we're at it, I have this running in my mbpv_custom_functions.module, how do I get dprint_r() working to print out all the $form array stuff ... I have devel installed and permissions set, but I cannot get the dprint_r to work.
Any help is appreciated.
In your
In your views-exposed-form.tpl.php file, do this;
dprint_r($form);
You can place the above like this;
Did exactly what I wanted it
Did exactly what I wanted it to do. Allowed me to quickly change the form submit button text. Thanks for posting it here.
Can somebody tell me why this
Can somebody tell me why this does not work:
The function is called, the IF statement is true, the variable output (devel dpm) shows that the values has been changed and cache cleared, but it has no affect on the form.
Quentin Campbell
changing the width using css
I used the method outlined here http://drupal.stackexchange.com/questions/21832/increasing-width-of-view...
So in my THEME.css I just placed one line:
#block-views-exp-VIEW_NAME-page input{width: 80px;}
to decrease the width of the field.
Exposed filters is a form
Talking about D7, exposed filters is a regular form, so you can theme, preprocess and alter it like other forms
$form_id = 'views_exposed_form', just in case
http://www.valthebald.net