Last updated March 26, 2011. Created by mroswell on August 8, 2008.
Edited by linclark, junedkazi. Log in to edit this page.
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);
}
?>For Drupal 6.x
<?php
function hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
$current_display = $form_state['view']->current_display;
$form['reset'] = array(
'#type' => 'markup',
'#value' => '<input '. drupal_attributes(array('type' => 'button', 'value' => t('Reset') )) .'class="form-submit" onClick="window.location = \'' .url($form_state['view']->display[$current_display]->display_options['path']) .'\';" />',
);
}
}
?>
Comments
Thank you for posting this.
Thank you for posting this.
Is there anything else I need to do? Because I tried this, and I cannot get it to work in Drupal 6.
Is there any text in the code that has to be changed?
Any settings in views?
I cleared the cache after uploading, but no result.
Has anybody had this working for them?
----
Have some spare time? Consider helping, and fixing bugs. :-)
same problem here ...
same problem here ...
I am using Drupal 6 and used
I am using Drupal 6 and used the hook_form_alter code mentioned above. It worked for me! I just placed the code in the views.module file of the views module.`
I am using the 'views hacks'
I am using the 'views hacks' module now. It has a submodule which adds a reset button. Worked for me.
I need to read up on how to use template.php better. It still eludes me sometimes understanding it. Can never seem to get code working in it. Adapting existing code in the template.php does seem to work. Maybe I have a conflict of code going on. I don't know.
----
Have some spare time? Consider helping, and fixing bugs. :-)