Last active
December 14, 2015 19:28
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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