Last updated December 22, 2008. Created by Gribnif on December 22, 2008.
Log in to edit this page.

It is possible to have more than one form element appear in the same table cell or <div> tag, simply by assigning them the same weight. When form_panel encounters this situation, it concatenates the form elements within the same containing tag.

Example:

<?php
  $form
= array(
   
'#theme' => 'form_panel_table',
   
'#form_panel_table_attributes' => array('border' => 1));
 
$i = ord('A');
 
$form[chr($i)] = array('#value' => chr($i++), '#weight' => 2001);
 
$form[chr($i)] = array('#value' => chr($i++), '#weight' => 2002);
 
$form[chr($i)] = array('#value' => chr($i++), '#weight' => 2002);
  print
drupal_render($form);
?>

  +---+----+
  | A | BC |
  +---+----+

The order of elements presented in this way depends on the order Drupal's Forms API code assigns to the elements. In this case, both the "B" and the "C" have the same weight, so they are ordered based upon their order of appearance in the $form array.

So, what if you wanted to reverse the order of "B" and "C" without changing the way the elements are stored in in the array? Because form_panel only looks at certain parts of the weight, it is possible to influence the outcome of Drupal's weight-based sorting. In the case of integer weights, anything following a decimal point will be ignored by form_panel.

For example, this modified code:

<?php
  $form
[chr($i)] = array('#value' => chr($i++), '#weight' => 2001);
 
$form[chr($i)] = array('#value' => chr($i++), '#weight' => 2002.2);
 
$form[chr($i)] = array('#value' => chr($i++), '#weight' => 2002.1);
?>

would produce:
  +---+----+
  | A | CB |
  +---+----+

A variation on this method can also be used with #form_panel_weights_decimal. In this case, the amount you need to add to the weight is 0.0001.

If, instead of using the weights to specify the row and column of your form elements, you use #form_panel_row and #form_panel_col, then the entire weight value is used for ordering within an individual cell.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.