Skip to main content
fixed the reference to the form builder function
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

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_form()search_box() doesn't use any value for the field's weight, which means the default value is used.

  $form['basic']$form[$form_id] = array(
    '#type' => 'container''textfield',
   
  '#attributes' => array('class''#title' => arrayt('container-inline')'Search'),
  );
  $form['basic']['keys'] = array(
    '#type''#title_display' => 'textfield''invisible', 
    '#title''#size' => $prompt15, 
    '#default_value' => $keys'', 
    '#size''#attributes' => $prompt ? 40array('title' :=> 20,t('Enter 
 the terms you wish '#maxlength'to =>search 255for.')),
  );
  // processed_keys is used to coordinate keyword passing between other forms
  // that hook into the basic search form.
  $form['basic']['processed_keys']$form['actions'] = array(
    '#type' => 'value',
    '#value' => '',
  'actions');
  $form['basic']['submit']$form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => 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(&$form, &$form_state) {
  $form['my_field'] = array(
    '#type' => 'select', 
    '#title' => t('whatever'), 
    '#options' => array(
      0 => 'option1',
      1 => 'option2',
    ), 
    '#default_value' => 255,
    '#weight' => -200,
  );
}

The search form appears as in the following screenshot.

screenshot

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_form() doesn't use any value for the field's weight, which means the default value is used.

  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield', 
    '#title' => $prompt, 
    '#default_value' => $keys, 
    '#size' => $prompt ? 40 : 20, 
     '#maxlength' => 255,
  );
  // processed_keys is used to coordinate keyword passing between other forms
  // that hook into the basic search form.
  $form['basic']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => '',
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );

I have used the following code in a test module.

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

The search form appears as in the following screenshot.

screenshot

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' => 'textfield',  
    '#title' => t('Search'), 
    '#title_display' => 'invisible', 
    '#size' => 15, 
    '#default_value' => '', 
    '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => 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(&$form, &$form_state) {
  $form['my_field'] = array(
    '#type' => 'select', 
    '#title' => t('whatever'), 
    '#options' => array(
      0 => 'option1',
      1 => 'option2',
    ), 
    '#default_value' => 255,
    '#weight' => -200,
  );
}

The search form appears as in the following screenshot.

screenshot

added 532 characters in body
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

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_form() doesn't use any value for the field's weight, which means the default value is used.

  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield', 
    '#title' => $prompt, 
    '#default_value' => $keys, 
    '#size' => $prompt ? 40 : 20, 
    '#maxlength' => 255,
  );
  // processed_keys is used to coordinate keyword passing between other forms
  // that hook into the basic search form.
  $form['basic']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => '',
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );

I have used the following code in a test module.

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

The search form appears as in the following screenshot.

screenshot

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_form() doesn't use any value for the field's weight, which means the default value is used.

  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield', 
    '#title' => $prompt, 
    '#default_value' => $keys, 
    '#size' => $prompt ? 40 : 20, 
    '#maxlength' => 255,
  );
  // processed_keys is used to coordinate keyword passing between other forms
  // that hook into the basic search form.
  $form['basic']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => '',
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );

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_form() doesn't use any value for the field's weight, which means the default value is used.

  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield', 
    '#title' => $prompt, 
    '#default_value' => $keys, 
    '#size' => $prompt ? 40 : 20, 
    '#maxlength' => 255,
  );
  // processed_keys is used to coordinate keyword passing between other forms
  // that hook into the basic search form.
  $form['basic']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => '',
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );

I have used the following code in a test module.

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

The search form appears as in the following screenshot.

screenshot

Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

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_form() doesn't use any value for the field's weight, which means the default value is used.

  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('container-inline')),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield', 
    '#title' => $prompt, 
    '#default_value' => $keys, 
    '#size' => $prompt ? 40 : 20, 
    '#maxlength' => 255,
  );
  // processed_keys is used to coordinate keyword passing between other forms
  // that hook into the basic search form.
  $form['basic']['processed_keys'] = array(
    '#type' => 'value',
    '#value' => '',
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );