Inserting a select box before the search box (Drupal 7) I am pretty new to Drupal dev world. I wanted to know how to insert a select box before the search box. I used the below code to alter the search form and set the #weight to a higher value but the select box still shows up after the search box.

function mymodule_form_search_block_form_alter(&amp;$form, &amp;$form_state) {
  $form['my_field']= array(
    '#type' =&gt; 'select', 
    '#title' =&gt; t('whatever'), 
    '#options' =&gt; array(
      0 =&gt; 'option1',
      1 =&gt; 'option2',
    ), 
    '#default_value' =&gt; 255,
    '#weight' =&gt; 10,
  );
}
If you need the form field to be placed before any other form field present in the form, you need to use, for the weight, a lower value than the one used from the present form fields. The default value is 0; use a negative value to be sure the form field is always shown first (e.g. −200).

search_box() doesn't use any value for the field's weight, which means the default value is used.

  $form[$form_id] = array(
    '#type' =&gt; 'textfield', 
    '#title' =&gt; t('Search'), 
    '#title_display' =&gt; 'invisible', 
    '#size' =&gt; 15, 
    '#default_value' =&gt; '', 
    '#attributes' =&gt; array('title' =&gt; t('Enter the terms you wish to search for.')),
  );
  $form['actions'] = array('#type' =&gt; 'actions');
  $form['actions']['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Search'),
  );
  $form['#submit'][] = 'search_box_form_submit';


I have used the following code in a test module.

function code_testing_form_search_block_form_alter(&amp;$form, &amp;$form_state) {
  $form['my_field'] = array(
    '#type' =&gt; 'select', 
    '#title' =&gt; t('whatever'), 
    '#options' =&gt; array(
      0 =&gt; 'option1',
      1 =&gt; 'option2',
    ), 
    '#default_value' =&gt; 255,
    '#weight' =&gt; -200,
  );
}


The search form appears as in the following screenshot.