Example: Add a 'Reset' Button to Exposed Filters

Last modified: August 8, 2008 - 05:13

To add a reset button to exposed views filters, add this function to your template.php. (Typically, you'll find that file in /settings/all/themes/MY_THEMENAME. You may also find it in /settings/all/themes/zen/MY_THEMENAME )

<?php
function phptemplate_views_filters($form) {
 
$view = $form['view']['#value'];

  foreach (
$view->exposed_filter as $count => $expose) {
   
$row[] = drupal_render($form["op$count"]) . drupal_render($form["filter$count"]);
   
$label[] = $expose['label'];
  }
 
$form['reset'] = array(
 
'#type' => 'markup',
 
'#value' => '<input '. drupal_attributes(array('type' => 'button', 'value' => t('Reset') )) .'class="form-submit" onClick="window.location = \'' .url($view->url) .'\';" />',
 
'#weight' => 19,
  );
 
$row[] = drupal_render($form['submit']) .drupal_render($form['reset']);

 
$label[] = ''; // so the column count is the same.

  // make the 'q' come first
 
return drupal_render($form['q']) . theme('table', $label, array($row)) . drupal_render($form);
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.