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...
...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.
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:
<?php
function phptemplate_views_filters($form) {
if ($form['#view_name'] == 'MYVIEW') {
$view = $form['view']['#value'];
$form['submit']['#value'] = 'Search';
$rows_theme = '';
foreach ($view->exposed_filter as $count => $expose) {
$rows_theme .= '<div class="filter ' . $form["filter$count"]['#name'] . '">';
$rows_theme .= '<label for="' . $form["filter$count"]['#id'] . '">'. $expose['label'] .'</label>';
$rows_theme .= drupal_render($form["op$count"]) . drupal_render($form["filter$count"]);
$rows_theme .= '</div>';
}
$rows_theme .= '<div>'. drupal_render($form['submit']) .'</div>';
return drupal_render($form['q']) . $rows_theme . drupal_render($form);
}
else {
return theme_views_filters($form);
}
}
?>
--
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.
<?php$view = views_get_view('MYVIEW');
$form = drupal_retrieve_form('views_filters', $view);
$form['#action'] = url($view->url);
drupal_process_form('views_filters', $form);
return drupal_render_form('views_filters', $form);
?>
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
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...
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:
<?php
function phptemplate_views_filters($form) {
if ($form['view']['#value']->name == 'MYVIEW') {
$view = $form['view']['#value'];
$form['submit']['#value'] = 'Search';
$rows_theme = '';
foreach ($view->exposed_filter as $count => $expose) {
$rows_theme .= '<div class="filter ' . $form["filter$count"]['#name'] . '">';
$rows_theme .= '<label for="' . $form["filter$count"]['#id'] . '">'. $expose['label'] .'</label>';
$rows_theme .= form_render($form["op$count"]) . form_render($form["filter$count"]);
$rows_theme .= '</div>';
}
$rows_theme .= '<div>'. form_render($form['submit']) .'</div>';
return form_render($form['q']) . $rows_theme . form_render($form);
}
else {
return theme_views_filters($form);
}
}
?>
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:
<?phpfunction phptemplate_views_filters($form) {
if ($form['#id'] == 'views-exposed-form-featured-sales-page-1') {
$form['field_bathrooms_value']['#size']=10;
$form['field_bedrooms_value']['#size']=10;
$form['field_neighborhood_value']['#size']=10;
$form['field_price_value']['#size']=10;
$form['submit']['#value']='Filter';
}
return theme_views_filters ($form);
}
?>