0

I have placed 2 search box in 'node/92' page at two different region one is at header region and another is at content region ,I have to change the placeholder text of both search box as abc and xyz respectively my code is:

function bartik_form_search_block_form_alter(&$form, &$form_state, $form_id) {      //print arg(1);  
      if (arg(1) == 92)
    {


    $form['search_block_form']['#attributes']['placeholder'] = t('abc ');
}

} 

but this code not working well after using it both the search box placeholder text having the same title "abc"

2
  • Additional comment to my earlier comment from a few mins ago: if you do NOT provide ANY feedback to answers, and if you do not upvote and/or accept anything, you take the risk that any of those who responded downvote your question ... which is probably why this question is downvoted also ... Just trying to help you avoid downvotes, ok? Let me know (via extra comment) you read what I wrote here, so that I can DELETE my comment here also ... After I notice some type of progress (from you) to any of the answers below, I might consider upvoting your downvote ... (= undo the current -1). Commented Nov 25, 2015 at 7:33
  • The placeholder attribute has to be set on the input text field. I suspect the key of that field is not "search_block_form" but something else. Commented Apr 4, 2018 at 8:22

2 Answers 2

0

By using hook_form_alter and/or any of its descendants, you are altering the placeholder everywhere and anywhere that the form occurs.

To isolate specific instances of the form, based on which region they are in, you can use hook_preprocess_page.

For example, in your template.php:

function yourthemename_preprocess_page(&$variables) {
  if (arg(1) == '92') {
     // Set the default value for the form in the header region.
    $variables['page']['header']['search_form']['search_block_form']['#attributes']['placeholder'] = t('abc');

     // Set the default value for the form in the content region.
    $variables['page']['content']['search_form']['search_block_form']['#attributes']['placeholder'] = t('def');
  }
}
1
  • That's incorrect - the OP is implementing hook_form_FORM_ID_alter(), which is for a specific form
    – Clive
    Commented Oct 8, 2015 at 12:20
0

jQuery may be a solution.

jQuery(document).ready(function(){ 
 jQuery('#id').attr("placeholder", "placeholder to show");
});

Your Answer

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