How to change “apply” button text in Drupal Views exposed filters

5 Jul

1) Open your current themes template.php file

2) append following function in it.

3)

function YOUR_THEME_NAME_preprocess_views_exposed_form(&$vars, $hook)
     {

         // only alter the required form based on id
            if ($vars['form']['#id'] == 'views-exposed-form-user-search-page-2') {
              // Change the text on the submit button
              $vars['form']['submit']['#value'] = t('Search');
              // Rebuild the rendered version (submit button, rest remains unchanged)
              unset($vars['form']['submit']['#printed']);
              $vars['button'] = drupal_render($vars['form']['submit']);
         }
      }

4) Now clear your cache and its done
You can clear cache at following location
/admin/settings/performance
scroll down to the bottom of the page and click “clear cached data” button.

IMPORTANT : Replace text “YOUR_THEME_NAME” in above function name with your current theme name like if you are using theme garland. function name will be garland_preprocess_views_exposed_form. Use firebug or view source and write your views form id in form id in ‘views-exposed-form-user-search-page-2′)

and t(‘Search’) inside this write the text which you want to appear on button instead of ‘Apply’.

3 Responses to “How to change “apply” button text in Drupal Views exposed filters”

  1. jim November 10, 2011 at 5:30 pm #

    Is it possible to add more than one form such as views-exposed-form-user-search-page-2 and views-exposed-form-user-search-block-1 and views-exposed-form-user-search-page-3?

    • Admin November 11, 2011 at 10:57 am #

      Yes,
      add or (||) conditions in if() as follows if you want to apply this code for multiple apply buttons on different forms

      if ($vars['form']['#id'] == ‘views-exposed-form-user-search-page-2′ || $vars['form']['#id'] == ‘views-exposed-form-user-search-block-1′ || $vars['form']['#id'] ==views-exposed-form-user-search-block-3)

      Hope this helps.

      Thanks

    • Nick December 6, 2011 at 11:47 pm #

      Brilliant! Many thanks for the solution. Works perfectly with my D7 site.

Leave a Reply

*