3

The following code is fairly standard for adding a submit button to the bottom of a form:

// Submit button.
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
);

It always appears at the bottom of the form so I assume it is assigned a 'heavy' #weight by default. Does anyone know its default value?

7

A submit button appears at the bottom of the form usually because it's simply added last in the form definition.

A submit button can still be placed anywhere and weighted using the #weight property.

The default weight is assigned automatically.

The relevant core code is in

form_builder

// Assign a decimal placeholder weight to preserve original array order.
if (!isset($element[$key]['#weight'])) {
  $element[$key]['#weight'] = $count/1000;
}
else {
  // If one of the child elements has a weight then we will need to sort
  // later.
  unset($element['#sorted']);
}

If not present the#weight property is calculated dynamically based on the count/item position while looping over the form element set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.