Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Last active December 14, 2015 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterjaap/5136453 to your computer and use it in GitHub Desktop.
Save peterjaap/5136453 to your computer and use it in GitHub Desktop.
This little snippet improves the 'forgot password' workflow in a Magento shop by adding a button (after a failed login attempt) that directly posts the email address to the forgot password action ----------- Idea inspired by http://www.alasdairmonk.com/journal/improving-the-forgotten-password-process/
Event.observe(window, "load", function(){
if(document.location.href.indexOf('customer/account/login')>0 && $$('ul.messages li.error-msg ul li span').length>0) { // check for login page and actual error message
$('pass').addClassName('validation-failed').focus(); // add red dotted lining & set focus to the password field
$('pass').insert({after: '<div class="validation-advice" id="advice-required-entry-pass" style="">Your password is incorrect.</div>'}); // add an error message below the password field
$$('div.buttons-set > a').first().remove(); // remove the Forgot Password link
$$('ul.messages li.error-msg ul li span').first().innerHTML+=' <a href="javascript:newPasswordSubmit()">Click here to reset your password</a>'; // add an actionable link to the error message
$('send2').insert({after: '<button type="button" class="button" title="Reset my password" name="send" id="forgotpass" onclick="newPasswordSubmit()"><span><span>Reset my password</span></span></button>'}); // add a reset my password button next to the login button
}
});
function newPasswordSubmit() {
$('pass').removeClassName('required-entry'); // remove validation for password because we don't need the post for the forgotpassword form
$('pass').removeClassName('validate-password'); // ^^
$('email').name = 'email'; // set the name to email for the forgotpassword action
$('login-form').action = $('login-form').action.replace('loginPost','forgotpasswordpost'); // change the action URL of the form
$('login-form').submit(); // submit!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment