0

Since these forms can get quite big sometimes, especially with a lot of files attached and default preview for them.

Related, but not the same: How can I display a form button on top of the form?

3 Answers 3

2

You can do that using hook_form_alter() and setting the weight of $form['actions'] to a very small negative number. Note that this applies only those buttons wrapped in $form['actions']. For other buttons that they aren't, you should add them manually.

function YOURMODULE_form_alter(&$form, &$form_state) {
  $form['actions']['#weight'] = -1000;
  // a button that is not wrapped in actions.
  // assuming it's id is 'submit'
  $form['submit']['#weight'] = -1000;
}
3
  • It's the answer for and from the related question I've mentioned. I'm not asking about my module, the question is about affecting all forms.
    – int_ua
    Commented Jun 1, 2014 at 5:53
  • This answer IS for all forms. You should place this code in your module.
    – Elin Y.
    Commented Jun 1, 2014 at 7:12
  • Guess I was distracted and didn't pay enough attention at the time.
    – int_ua
    Commented Nov 5, 2020 at 20:15
1

The module for that is part of the Util package and is called, unsurpsingly, Top Buttons.

Drush:

drush dl util
drush en -y top_buttons
1

Adding to the answer above, #weight needs to be accessed with a preceding #. Also, you should check if the form elements exist before modifying them to avoid getting warnings in your logs.

Something like the below might work:

function YOURMODULE_form_alter(&$form, &$form_state) {
  if (isset($form['actions'])) {
    $form['actions']['#weight'] = -1000;
  }
  if (isset($form['submit'])) {
    $form['submit']['#weight'] = -1000;
  }
}

Also, this solution assumes you have a custom module for your site. If you don't, you'll need to research how to set one up first.

1
  • This code would go in your own module, but would effect forms from any module. hook_form_alter() runs on every form. Commented Jun 7, 2014 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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