Add element to the beginning of form, via hook_form_alter() Using Drupal 7, I'm trying to utilize Drupal Form API in combination with hook_form_alter to place my added inputs at the beginning of the form.

I thought the best way to do this was to create a new form element like so:

$form['program_list'] = array(
    '#type' =&gt; 'select', 
    '#title' =&gt; t('Select a preferred Program'), 
    '#options' =&gt; $program_list,
    '#weight' =&gt; -1,
);


I read the documentation, and it looks like there is a #weight attribute. I tried setting the weight to either 0 and negative integers, but my added inputs are still at the bottom.

I then used var_dump() to check the weights of my Webform-generated inputs. They were as I expected: a 0-based, incremental weight index.

I also tried placing the elements in $newform then  using $form = $newform + $form, but that as well placed my new inputs at the bottom of the form.

What am I doing wrong?
I was facing the same problem but found the answer thanks to this post: http://drupal.org/node/235354

Problem was that the field I was adding to my web form was not in a group when all the already existing fields were part of the group 'submitted' maybe because this is a webform. So setting the weight to -1000 didn't change anything.

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

    $form['my_new_field_name'] = array (
      '#type' =&gt; 'checkbox',
      '#title' =&gt; t ('My new field is after the others'),
      '#weight' =&gt; -1000,
    );

}


To correctly make it work I just needed to create my new field inside the group 'submitted' like that :

$form['submitted']['my_new_field_name'] = array (...