Skip to main content
edited tags
Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91
removed the question already answered
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

basic understanding How do I alter the text of hook_alterthe input field in the search form?

I am sorry for asking what is a basic question. I have tried looking for an answer to this nagging question but have found none.

These "general knowladge" questions come from a concrete task. I need to alter the text of the search input field. In my quest to do this, I have dpm() the contentscontent of $form on a call to hook_form_search_box_form_alter(). The output is belowthe following.

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

        )

    [actions] => Array
        (
            [#type] => actions
            [submit] => Array
                (
                    [#type] => submit
                    [#value] => Search
                )

        )

    [#submit] => Array
        (
            [0] => search_box_form_submit
        )

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

        )

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

        )

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

    [#tree] => 
    [#parents] => Array
        (
        )

    [#validate] => Array
        (
        )

    [#theme] => Array
        (
            [0] => search_block_form
            [1] => search_box
        )

)

My questions are:Is $form['search_block_form']['#title'] = ''; the right thing to do here?

  1. Assuming my goals, altering $form['search_block_form']['#title'] = ''; is the right thing to do here? (I have more questions on this point but for brevity...)
  2. What is the difference between array elements that have a leading pound in the name from those that do not. Example $form['actions'] and $form['submit']


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

        )

    [actions] => Array
        (
            [#type] => actions
            [submit] => Array
                (
                    [#type] => submit
                    [#value] => Search
                )

        )

    [#submit] => Array
        (
            [0] => search_box_form_submit
        )

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

        )

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

        )

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

    [#tree] => 
    [#parents] => Array
        (
        )

    [#validate] => Array
        (
        )

    [#theme] => Array
        (
            [0] => search_block_form
            [1] => search_box
        )

)



basic understanding of hook_alter

I am sorry for asking what is a basic question. I have tried looking for an answer to this nagging question but have found none.

These "general knowladge" questions come from a concrete task. I need to alter the text of the search input field. In my quest to do this I have dpm() the contents of $form on a call to hook_form_search_box_form_alter(). The output is below.

My questions are:

  1. Assuming my goals, altering $form['search_block_form']['#title'] = ''; is the right thing to do here? (I have more questions on this point but for brevity...)
  2. What is the difference between array elements that have a leading pound in the name from those that do not. Example $form['actions'] and $form['submit']


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

        )

    [actions] => Array
        (
            [#type] => actions
            [submit] => Array
                (
                    [#type] => submit
                    [#value] => Search
                )

        )

    [#submit] => Array
        (
            [0] => search_box_form_submit
        )

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

        )

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

        )

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

    [#tree] => 
    [#parents] => Array
        (
        )

    [#validate] => Array
        (
        )

    [#theme] => Array
        (
            [0] => search_block_form
            [1] => search_box
        )

)



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] => Array
        (
            [#type] => textfield
            [#title] => Search
            [#title_display] => invisible
            [#size] => 15
            [#default_value] => 
            [#attributes] => Array
                (
                    [title] => Enter the terms you wish to search for.
                )

        )

    [actions] => Array
        (
            [#type] => actions
            [submit] => Array
                (
                    [#type] => submit
                    [#value] => Search
                )

        )

    [#submit] => Array
        (
            [0] => search_box_form_submit
        )

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

        )

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

        )

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

    [#tree] => 
    [#parents] => Array
        (
        )

    [#validate] => Array
        (
        )

    [#theme] => Array
        (
            [0] => search_block_form
            [1] => search_box
        )

)

Is $form['search_block_form']['#title'] = ''; the right thing to do here?

Source Link

basic understanding of hook_alter

I am sorry for asking what is a basic question. I have tried looking for an answer to this nagging question but have found none.

These "general knowladge" questions come from a concrete task. I need to alter the text of the search input field. In my quest to do this I have dpm() the contents of $form on a call to hook_form_search_box_form_alter(). The output is below.

My questions are:

  1. Assuming my goals, altering $form['search_block_form']['#title'] = ''; is the right thing to do here? (I have more questions on this point but for brevity...)
  2. What is the difference between array elements that have a leading pound in the name from those that do not. Example $form['actions'] and $form['submit']

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

        )

    [actions] => Array
        (
            [#type] => actions
            [submit] => Array
                (
                    [#type] => submit
                    [#value] => Search
                )

        )

    [#submit] => Array
        (
            [0] => search_box_form_submit
        )

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

        )

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

        )

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

    [#tree] => 
    [#parents] => Array
        (
        )

    [#validate] => Array
        (
        )

    [#theme] => Array
        (
            [0] => search_block_form
            [1] => search_box
        )

)