Theme views exposed filters (search filter) fields

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:

<?php
/* 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 :)

But for those who don't know php...

airali - February 15, 2008 - 15:54

...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

calebtr - March 11, 2008 - 22:51

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

Prodigy - August 26, 2008 - 21:14

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.

 
 

Drupal is a registered trademark of Dries Buytaert.