I'm using Search API Solr Search and can't seem to get a placeholder attribute in it. I've tried using hook form alter as I would on a normal search block, but doesn't seem to work with search api solr.

The id of the form = views-exposed-form-recipe-find-recipe-find-list
The name of the search input field = search_api_views_fulltext

I've placed this function in my theme's template.php...

function marigold_institute_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'views_exposed_form_recipe_find_recipe_find_list') {
    $form['search_api_views_fulltext']['#attributes']['placeholder'] = t('Search by name or ingredient');

I'm not quite sure what I'm doing wrong. This is the first time I've tried using hook_form_alter, so I could easily be missing something obvious. I tried the function on a normal search block using "search_block_form" for the id and name, and it worked. I just can't seem to get it working with search api solr search.

1 Answer 1


The problem is the views exposed filter form always has an ID of "views_exposed_form", nothing more specific. My low-rent way round it was this:

function MYMODULE_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('blah');

That works fine for my use case, but if you need something more specific you should be able to look in the $form or $form_state and find the View object, which you can use to identify which view/display is currently being altered.

  • How do I look in the $form or $form_state?
    – mlanning
    Nov 30, 2013 at 16:14
  • Install the Devel module if you haven't already, and use dpm($form);, that will print the array out to the messages area
    – Clive
    Nov 30, 2013 at 16:17
  • Okay. It's not easy being such a newbie. Thank you for your help... I don't think I'm doing this right. I put dpm($form); on a new line in my template.php. I get a green area with a check in the messages area, but it's blank. There's no information.
    – mlanning
    Nov 30, 2013 at 16:30
  • It's working now. I found that I had a module that may have been interfering with it. It is a sandbox project drupal.org/sandbox/berliner/2087181 MEFIBS - More exposed forms in blocks. I disabled it, and I got the placeholder text. Then I went back, enabled MEFIBS again, and the placeholder text is still there! I'm glad that it's there and I got it working, but a little bummed that I'm not sure why... Still learning. Thanks again for the help.
    – mlanning
    Nov 30, 2013 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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