l008comm - 10:10 pm on Jan 1, 2013 (gmt 0)
I am having a hell of a time getting browser auto-complete to work.
My 1st design of the login form was so simple. It wasn't a form at all. It was just two inputs. A keyup event listener would see if you hit return in either field. If you did, after some validation, it would log you in by making an HTTP request to a PHP doc. Then it would refresh the current page and BAM, the page would reload but you'd be logged in, so the content would be different. This was a great, sleek, simple solution that worked great, with only one flaw... no AutoComplete. My assumption was that, no <form>, no AutoComplete.
Also, FYI, this login form is built into the thin header at the top of every page on the site. I don't have a separate, dedicated login page.
So my plan B was to simply wrap the two inputs in a form tag. Remove my keyup listener, and instead make a submit listener that, when a form was submitted, would intercept it and log you in essentially the same way. But I thought that would count as a "physical" form submit, and I'd get my browser AutoComplete/AutoFill. No luck. I found an article that said you need an action attribute and a submit button. I added an action attribute, and an invisible submit button. Still no luck. I do not want a visible submit button so I did not try that.
So plan C had me going back to keyup listeners in the inputs. I'd listen for a return, and make a form submit event. Then I had my code handle that form submission with a submit event listener. Logically, it seemed a little clumsy but it if worked, I'd be happy. Still no AutoComplete.
So then I came up with plan D but I haven't tried it yet. I'm done trying thing, i need to know EXACTLY what causes browsers to ask to remember your login/password. No more guesswork. I test in a wide array of browsers, and they all seem to be in agreement about when they do or do not ask, so I don't think this is going to be different among different browsers.
So my plan D is: instead of using a dummy action in my form, have the real login.php document. So when the form is submitted, your credentials would be verified via an ajax request. But if they were good, it wouldn't send another ajax request to log you in. Instead, it would do nothing, and let the form "really" submit to the login page, which would log you in and then redirect you back to the HTTP_REFERER url.
Plan D is not as graceful, but I suspect you'd have to be paying pretty close attention to really notice it being not as slick as the other plans. I'm certain D would work, as far as a way to log you in. But will it finally be enough of a form submission, to cause an AutoComplete prompt?