2

How to make a custom register button in the user login form (block) so that it redirects to 'user/register' ?

Currently, when I click my custom "Register" button, the code in _mymodule_register is executed (I debugged), but the page just reloads, it does not go to user/register. I tried both drupal_goto and form redirect, but nothing works.

function mymodule_form_user_login_block_alter(&$form, $form_state, $form_id) {
  $form['actions']['register'] = array(
    '#type' => 'submit',
    '#value' => t('Register'),
    '#submit' => array('_mymodule_register'),
    '#limit_validation_errors' => array(),
  );
}

function _mymodule_register($form, $form_state) {
  $form_state['redirect'] = 'user/register';
  //drupal_goto('user/register');
}
1

Use below code to achieve the same functionality.

function mymodule_form_user_login_block_alter(&$form, $form_state, $form_id) {
  $form['actions']['register'] = array(
    '#markup' => l('Register', 'user/register'),
  );
}

Theme it using css to look like a button. Done !

  • Thanks, that's a good tip! In order to achieve exactly the same look between the true "Login" button and the "Register" link, I had to style also the standard "Login" button (with exactly the same class as "Register" link). This required adding the class to the input submit form element, by adding this line of code at the bottom of the above function: $form['actions']['submit']['#attributes']['class'][] = 'mybutton'; - now the button and the link look the same – camcam Oct 2 '12 at 14:27

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.