How to positioning a field before another specific field with hook_form_alter() I'm modifying a form by adding another text input, and I need to add this input right before a field. How do i do it? this is my code and it's working correctly:

function provintegra_form_alter(&amp;$form, &amp;$form_state, $form_id) {

    $form['input_latitude'] = array(
      '#type' =&gt; 'textfield', 
      '#title' =&gt; t('Search address'), 
      '#default_value' =&gt; '',
      '#prefix' =&gt; '&lt;div id="map"&gt;Mappa qui&lt;/div&gt;',
    );

}


I just need to position this before $form['field_latitude'].
Set the weight property of your required lower than other.

$form['field_latitude']['#weight'] = 0;
$form['input_latitude']['#weight'] = -10;

or
function provintegra_form_alter(&amp;$form, &amp;$form_state, $form_id) {

$form['input_latitude'] = array(
  '#type' =&gt; 'textfield', 
  '#title' =&gt; t('Search address'), 
  '#default_value' =&gt; '',
  '#prefix' =&gt; '&lt;div id="map"&gt;Mappa qui&lt;/div&gt;',
  '#weight' =&gt; -10,
);


}