Influence the ordering of 2 (or more) forms on 1 site

Matthias Weiss's picture
Matthias Weiss

I'm working on a project where we have a site with form_builder displaying its drag and drop form but above that we wanted a select box and a separate submit button being displayed.

First we created the site containing the select box form and the form_builder form with:

$form[0] = drupal_get_form('my_select_box_form');

...

foreach (form_builder_interface('webform', $nid) as $k => $f) {
  $form[$k + 1] = $f;
}

The problem was, that the select box was displayed below the form_builder form. The solution to this was this additional line of code after the drupal_get_form call:

$form[0]['#weight'] = -1000;

With other words, it's not only possible to change the ordering of single fields within a form using the #weight property for each field but we can change the ordering of whole forms too.

Comments

Add new comment