How do I alter the text of the input field in the search form? I need to alter the text of the search input field. In my quest to do this, I have  dpm() the content of $form on a call to hook_form_search_box_form_alter(). The output is the following.

Array
(
    [search_block_form] =&gt; Array
        (
            [#type] =&gt; textfield
            [#title] =&gt; Search
            [#title_display] =&gt; invisible
            [#size] =&gt; 15
            [#default_value] =&gt; 
            [#attributes] =&gt; Array
                (
                    [title] =&gt; Enter the terms you wish to search for.
                )

        )

    [actions] =&gt; Array
        (
            [#type] =&gt; actions
            [submit] =&gt; Array
                (
                    [#type] =&gt; submit
                    [#value] =&gt; Search
                )

        )

    [#submit] =&gt; Array
        (
            [0] =&gt; search_box_form_submit
        )

    [#form_id] =&gt; search_block_form
    [#type] =&gt; form
    [#build_id] =&gt; form-Y0XlzH4YO-EqVHxg5wnRf-PrnecuUSGdo5LTCPcLgLU
    [form_build_id] =&gt; Array
        (
            [#type] =&gt; hidden
            [#value] =&gt; form-Y0XlzH4YO-EqVHxg5wnRf-PrnecuUSGdo5LTCPcLgLU
            [#id] =&gt; form-Y0XlzH4YO-EqVHxg5wnRf-PrnecuUSGdo5LTCPcLgLU
            [#name] =&gt; form_build_id
            [#parents] =&gt; Array
                (
                    [0] =&gt; form_build_id
                )

        )

    [form_id] =&gt; Array
        (
            [#type] =&gt; hidden
            [#value] =&gt; search_block_form
            [#id] =&gt; edit-search-block-form
            [#parents] =&gt; Array
                (
                    [0] =&gt; form_id
                )

        )

    [#id] =&gt; search-block-form
    [#method] =&gt; post
    [#action] =&gt; /
    [#theme_wrappers] =&gt; Array
        (
            [0] =&gt; form
        )

    [#tree] =&gt; 
    [#parents] =&gt; Array
        (
        )

    [#validate] =&gt; Array
        (
        )

    [#theme] =&gt; Array
        (
            [0] =&gt; search_block_form
            [1] =&gt; search_box
        )

)


Is $form['search_block_form']['#title'] = ''; the right thing to do here?
@NoSssweat has provided a link, it is the answer if you want to alter a placeholder.

But reading your question I am getting other indications also.

FOR D7:

Case-1: If I read the sentence from your question "I need to alter the text of the search input field" I think you are talking about the placeholder, Now what is placeholder- you can see in following image the word "Search the site" in the text-area is called place-holder.



Case-2: But if I read your last sentence, "Is $form['search_block_form']['#title'] = ''; the right thing to do here?" then it talks about other things, this is corrosponds to Text appear when you hover on the input text-area("Enter the terms you wish to search for") as shown in following image.



I will explain both of that, The best tutorial for this is available here: How to Customize the Block Search Form.

Case-1 Paste the following code in your theme's template.php file, change the YourThemeName with your actual theme-name, save &amp; clear the cache.

function YourThemeName_form_search_block_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    $form['search_block_form']['#attributes']['placeholder'] = t('Search the site');
}


Case-2

function YourThemeName_form_search_block_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    $form['search_block_form']['#attributes']['title'] = t('Place a new sentence');
}




Case-3: If you want title on the block, you can just go to block configuration and put the title whatever you want, it will appear as a title of the Block.

 

FOR D8: as @NoSssweat pointed out in the following comment, how to do in D8. Hence, I am just repeating that comment here as it is needed.

function YourThemeNAme_form_search_block_form_alter(&amp;$form, FormStateInterface $form_state) {
  $form['keys']['#attributes']['placeholder'] = t('The new placeholder');
}