I have added a "register" button to the login form which is shown as a block on my homepage. I want the button to simply redirect to the registration page but it's POSTing to login and error'ing -- any ideas?

  function MYMODULE_form_user_login_alter(&$form, &$form_state) {
    $form['actions']['register'] = array(
      '#type' => 'submit',
      '#value' => t('Sign Up'),
      '#submit' => array('_user_login_register_submit')

  function _user_login_register_submit($form, &$form_state) {

It's not working because the login form validate handler is executed, and fails, before the function you call with the #submit attribute.

You can use #validate like a workaround probably, but there's a cleaner way to achieve what you are after.

I wouldn't create a button element at all. Make it a link to user/register instead and style it to look like a button if needed.

  • A link is a more elegant solution...didn't even think of that. Thanks :) – Alex.Barylski Apr 14 '14 at 3:14

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.