2

I am trying to add another button to a user login form. I am able to get the button to show up, but not to link to an external URL (example.org in the code below). Code I am using is below:

<?php

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'user_login' || $form_id == 'user_login_block') {
    $form['change_pass'] = array(
      '#type' => 'button',
      '#prefix' => '<div class="form-actions form-wrapper" id="change_pass">',
      '#suffix' => '</div>',
      '#value' => t('Change Password'),
      '#weight' => 1000,
      '#submit' => array('MYMODULE_change_pass_submit'),
      '#limit_validation_errors' => array(),
    );
  }
}

function MYMODULE_change_pass_submit($form, &$form_state) {
  drupal_goto('https://example.org', array('external' => TRUE));
}

Any thoughts?

1
2

You should use $form_state['redirect'] to redirect in form submit instead of drupal_goto ,I mean

function MYMODULE_change_pass_submit($form, &$form_state) {

  $form_state['redirect'] ='https://example.org';
}

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.