I'm trying to add two links on custom user form. The goal is this links to be displayed bellow the submit button. I've tried with weight property, but it's not working.

What do I miss?

This is my code:

      function custom_alter_form_alter (&$form, &$form_state, $form_id) {

        switch ($form_id) {
                case 'user_login':

                $form['name']['#title'] = t('Username');
                $form['pass']['#title'] = t('Password');
                $form['actions']['submit']['#value'] = t('Login');
                $form['actions']['submit']['#weight'] = 0;

                $form['page'] = array(
                '#markup' => '<h2>Login</h2>',
                '#weight' => -10,

                $form['register'] = array(

                '#type' => 'markup',    
                '#markup' => '<div class="user-login-register">You don't have an account?
                <a class="user-login-register" href="/user/register">  Click here</a></div>',
                '#weight' => 1,

                $form['password_reset'] = array(
                '#markup' => '<a class="user-login-password-reset" href="/user/password"> You forgot your password</a>',
                '#weight' => 2,


  • It should work if you increase the weight - try using higher number instead. Oct 14, 2013 at 8:29
  • I've set #weight property on submit button to -5 and #weight 20 and 21 on custom links, but the submit button is still down bellow. Oct 14, 2013 at 8:32

1 Answer 1


This line:

$form['actions']['submit']['#weight'] = 0;

only sets a submit's weight inside actions container.

To push actions to the top of the page, you need to affect it's own weigh:

$form['actions']['#weight'] = 0;

and if you want to move only one button, you can restructure your form by moving this button outside actions container:

$form['submit'] = $form['actions']['submit'];
$form['submit']['#weight'] = 0;

Note that this may break some forms that expect submit button in it's exact original place in form structure.

  • Thank you. I've set $form['actions']['#weight'] = 10; and now it's OK. It very logical, but I didn't know that I can set weight outside the submit actions container. I've learned very useful detail, thanks to you. Oct 14, 2013 at 8:43
  • 2
    @user2519032 you can add '#weight' to any form element which name does not start with # :)
    – Mołot
    Oct 14, 2013 at 8:45
  • How to set weight if we want submit button to show both on top and bottom?
    – Rick
    Dec 16, 2019 at 20:19

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.