1

i have been looking for a solution all day, i need some help. I created a single search box using views combine exposed filters. i am using bartik theme. On the exposed filter, i have added some default text using the following code in my template.php file as per this code snippet:

function bartik_form_views_exposed_form_alter(&$form, &$form_state) {
  if (!isset($form_state['view']->exposed_input['combine'])) {
    // OK to set the default value
    $form_state['input']['combine'] = 'Find Professionals';
  }
}

So far, my default text is showing, but i need to achieve 2 things:

  1. Make default text to disappear when user clicks on the search box
  2. Prevent user from searching default text.

ps: "combine" is the name of my views exposed filter, while "views_exposed_form" is the form id.

Thanks for your help in achieving this.

1

@Bala You actually pointed me in the right direction by mentioning "placeholder", I have also added that word to the question, Thanks for the help, so i did more research since i wanted to avoid enabling 2 modules because of only one exposed filter (i have many modules enabled already), so adding this code to my theme's template.php file as per this comment worked perfectly for me:

<?php
function yourtheme_form_alter(&$form, &$form_state, $form_id){
  if($form_id == "views_exposed_form"){
    if (isset($form['combine'])) {
            $form['combine']['#attributes'] = array('placeholder' => array(t('Find Professionals')));
    }
  }
}
?>

For benefit of novices, "yourtheme" in the function should be replaced with the name of your theme, 'combine' is the name of my exposed filter (You Can find yours by right-clicking the form on firefox or google chrome and clicking "inspect element").

This solution works for drupal 7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.