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' => 'select',
'#title' => t('Select a preferred Program'),
'#options' => $program_list,
'#weight' => -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?