1

I was creating my first project with drupal and now my problem was the request new password since this is a link and i want to make it into buttons so i generate my hook_form_alter but i got a problem with the url i'm not sure if markup is working.

Here my code for form_alter:

  $form['actions']['request'] = array(
'#markup' => l(t('Forgot Password?'), 'user/password', array('attributes' => array('class' => 'form-request','title' => t('Request a new generated password via e-mails.')))),'#weight' => 2, '#type' => 'button' );

I'm not sure if this is correct. Thanks for the help folks!

2
  • you want a linkable button instead of link?
    – Aboodred1
    Commented May 1, 2013 at 19:30
  • ^ yeah sorry for my bad english :) actually the button is working but my problem it direct to login not in user/password Commented May 1, 2013 at 19:40

1 Answer 1

2

Here how your code should look like:

/**
 * Implement hook_form_alter().
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {

  if($form_id == 'FORM_ID') {
    $form['actions']['request'] = array(
      '#type' => 'submit',
      '#value' => t('Forgot Password?'),
      '#submit' => array('mycustom_submit_redirect'),
      '#limit_validation_errors' => array(),
      '#attributes' => array(
        'class' => array('form-request'), 
        'title' => array(t('Request a new generated password via e-mails.')),
      ),
      '#weight' => 2, 
    );
  }
}

function mycustom_submit_redirect(&$form, &$form_state) {
  // sometimes it seems to fail
  //$form_state['redirect'] = 'user/password';

  // alternative method to redirect
  $options['absolute'] = TRUE;

  $url = url('user/password', $options);

  header('Location: ' . $url);

  drupal_exit($url);
}
8
  • still not working anyway i want to hook only at user_login_block Commented May 1, 2013 at 20:33
  • one thing i encounter are this no error message like this one "Username field is required. Password field is required" but the url still /?q=node&destination=node Commented May 1, 2013 at 20:45
  • did you clear drupal cache after you implemented the new changes? Also did you replace FORM_ID with the desired form
    – Aboodred1
    Commented May 1, 2013 at 20:48
  • replace FORM_ID with user_login_block
    – Aboodred1
    Commented May 1, 2013 at 20:49
  • opps after i try it to other browser it direct only at /?q=node :( Commented May 1, 2013 at 21: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.