1

I'm trying to get some placeholder text working for the Search API form, but have a different placeholder on the front page. Here's what I have so far which does work everywhere...

function THEME_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['search_api_views_fulltext'])) {
    $form['search_api_views_fulltext']['#attributes']['placeholder'] = t('Search Text here...');
  }
}

How can I get this working on only the front page, with a different placeholder text on all other pages? I've tried many things and totally stumped at the moment. Any help would be appreciated.

0

Check for drupal_is_front_page()

Return value

Boolean value: TRUE if the current page is the front page; FALSE if otherwise.

function THEME_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['search_api_views_fulltext']) && drupal_is_front_page()) {
    $form['search_api_views_fulltext']['#attributes']['placeholder'] = t('Search Text here...');
  }
}

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.