Browser won't prompt to save password - forms

This is quite a common question but the solutions I found in other people posts are either related to a specific browser (mostly firefox) or incorrect usage of names (name="U12-678132-34")
My issues are with browsers other then Firefox (Firefox all ways works).
The form that I use is pretty standard HTML form but the submission of it is done with javascript (jQuery AJAX).
Firefox all ways asks to remember the password (if it is a new user) and refills the form if you land on that same page again. But when it comes to Chrome/Safari/IE8-9 then they never request to save a password if the form is submitted with javascript.
(By the way I did check if the browsers dont have the - never remember passwords turned on)
My submit happens when you click on the link inside the form or if you just click the "ENTER" button on your keyboard, then it initiates the $.submit() method.
Is there a specific way that the submit needs to occur so that the browser would request to save a password like firefox does? or is there a way to at least tell a specific browser like Chrome/IE to force that type of request?
Form example:
<form class="loginform" method="post" action="">
<div class="inputfield">
<input name="email" type="text" class="emailaddress inputclass" value="" title="Email Address" />
</div>
<div class="inputfield">
<input name="password" type="password" class="password inputclass" title="Password" value="" />
</div>
<div class="submit">
<div class="checking">
<img src="/preloaders/login-preloader.png"/>
</div>
<input type="submit" name="submit" value="submit" style="display:none"/>
</div>
</form>

This is browser behaviour and can't really be changed. Firefox might be "smart" enough to offer to save passwords without the form actually being submitted, but that risks having buttons in the form also trigger that option even if the button does something different. So in my opinion, it's a bad thing for Firefox to do (I've had many problems with Firefox submitting forms even though it shouldn't).
If you really want the save password option to show up, use an iframe and submit to the iframe, instead of using AJAX. You could then use AJAX from the iframe to keep the old behaviour.

attach click event to your submit button
$('#id_of_submit').click(function() {
/your ajax logic
return false;
});
and on link
$('#id_of_your_link').click(function() {
$('#id_of_submit').click();
});
this will do the trick.

Looking at the answer accepted on here - How can I get browser to prompt to save password? - it seems that a valid action might help.
But i would suggest its down to browser behaviour and cannot be controlled by HTML and/or JavaScript. If you want to remember the values entered use a Cookie

As u r doing an AJAX post, then-
Remove the <form> tags
instead of <input type="submit", use button
take the field values & AJAX post- on button click event
it might do the trick.

One of the reason is that site should have a valid certificate. If it is not secured site, password save prompt will not appear after login.

Related

How to scrape a form that requires field validation by user?

I'm trying to scrape prices from this site:
https://www.pensketruckrental.com/quote/start.html
I can easily enter the form data, and I can activate the "Get A Quote" button and click it.
What I can't seem to do is get the form data to submit using a web scraper (I'm just doing it in VBA). When I input text using the scraper, the button remains grayed out, and even making a .click call on the button just displays errors on the form telling you not to leave the fields blank. Apparently it only recognizes data when you use an input device?
The code for one of the required fields, pickupLocation, is the following when I enter it manually (and thus the button works and the form can be submitted):
<input
type="text"
id="pickUpLocation"
name="pickUpLocation"
class="penskeValidateField penskeGoogleTypeAhead penskeInlineError ng-isolate-scope ng-touched ng-focused ng-dirty ng-valid-penske-err_loc_empty_sa ng-valid ng-valid-parse ng-valid-required"
aria-invalid="false"
aria-required="false"
country="rentalEntryCtrl.formItems.country"
penske-validate-field="pickuplocation"
required=""
autocompelete="off"
data-penske-placeholder="rentalEntryCtrl.activePlaceHolders.pickUpLocation"
ng-model="rentalEntryCtrl.formItems.pickupLocationSearchCriteria.address"
autocomplete="off">
And when I enter the data automatically using my scraper the tag & attributes read as follows:
<input
type="text"
id="pickUpLocation"
name="pickUpLocation"
class="penskeValidateField penskeGoogleTypeAhead penskeInlineError ng-pristine ng-isolate-scope ng-invalid ng-invalid-required placeholder ng-touched"
aria-invalid="true"
aria-required="true"
country="rentalEntryCtrl.formItems.country"
penske-validate-field="pickuplocation"
required=""
autocomplete="off"
data-penske-placeholder="rentalEntryCtrl.activePlaceHolders.pickUpLocation"
ng-model="rentalEntryCtrl.formItems.pickupLocationSearchCriteria.address"
autocompelete="off">
So of course I tried to copy the fields in the first code block into the second code block using setAttribute(), but even though I could change the attributes, I still couldn't get the form to submit properly.
I've looked at others that have dealt with something somewhat similar with autocorrect; their solutions have involved looking at the header and responses and just using the straight XHR to loop through the autocomplete queries, but the pricing information I'm scraping comes after several pages of form submissions, so that's not an option here.
I'm stuck I think; any ideas on how to populate the form and click the button/submit via my scraper?

If a form is missing the submit button, will the form still work to bots?

As a security measure, if I replace the <button type="submit"> with a <a class="button"> will the form still work for bots?
Normally yes, unless you check server side for that button being submitted along with the form.
If the form still has an action attribute attached to it, then it can still be submitted.
Try this for example:
document.getElementById("yourform").submit()

How do I get jQuery Mobile to redirect to a new page?

I'm trying to use Jquery Mobile for a web-app, and depending on what button the user clicks, redirect them to a new web page.
Example:
A user visits foo.com/index.php.
When they click login it takes them to foo.com/login.php.
That much I've been able to figure out using:
<a class="ui-block-a" data-role="button" type="submit" onclick="window.location.replace('./login.php');">Login</a>`
When I try setting href to "./login.php", it sends me to foo.com/#./login.php.
That is all well and good, but the web browser is really going to:
foo.com/index.php
foo.com/index.php#undefined
foo.com/login.php
which is causing a problem because the user has to click the back button twice.
How can I send the user from index.php to login.php without the browser trying to go to #undefined first?
I also tried:
<a class="ui-block-a" data-role="button" type="submit" onclick="window.location.replace('./login.php');" href="">Login</a>
but it still sends the viewer to foo.com/index.php# before redirecting properly.
<a href="javascript:location.replace('./login.php');" class="ui-block-a" data-role="button" type="submit" >Login</a>
Also, have you considered just simply linking to the page normally but with an attribute of rel="external" ?
try making it window.location.replace('login.php');
or window.location.replace('/login.php');

Is it possible to implement cross-browser username/password autocomplete in GXT?

Last night, I did a quick spike to try and implement username/password autocomplete in my GXT application. By "autocomplete", I don't mean Ajax-style autocomplete, but rather browser-based autocomplete. The best information I found on this via google is in the following post:
http://osdir.com/ml/GoogleWebToolkit/2009-04/msg01838.html
I didn't use this technique because I'm using GXT and didn't want to lose the look-and-feel of my login form.
I was successful in getting everything to work in Firefox (it populates both the username and password). In IE, it only populates the username, not the password. In Safari/Chrome, it doesn't work at all.
Here's how I did it:
Created a hidden HTML form on my HTML page that embeds GWT.
<form method="post" action="javascript:void(0)" style="display: none">
<input type="text" id="username" name="username" value=""/>
<input type="password" id="password" name="password" value=""/>
<input type="submit" value="Login" id="login"/>
</form>
When a user clicks on the "Login" button in my GWT application, populate the fields in this hidden form and "click" on the Login button (which will do nothing since the action="javascript:void(0)".
// Set the hidden fields to trigger the browser to remember
DOM.getElementById("username").setAttribute("value", username.getValue());
DOM.getElementById("password").setAttribute("value", password.getValue());
clickFormLogin();
...
public static native void clickFormLogin() /*-{
$doc.getElementById("login").click();
}-*/;
This works in Firefox 3.5 and prompts me to save the user/pass at the top of the screen. I believe I know why this doesn't work in Safari/Chrome and that's because the form's action doesn't go anywhere and the form is not submitted. If I change the action to be an actual URL and show the form, clicking on the form's Login button will save it in those browsers.
After typing this up as a question here, I got to thinking this might make a good blog post. Therefore, I copied everything and added a bit to my blog:
http://raibledesigns.com/rd/entry/browser_based_username_password_autocomplete
Summary and Question
While I'm glad I got it working in Firefox, I'm disappointed with IE's lack of password autocompletion. More than anything, I can't help but think there's a way to make this work in WebKit-based browsers.
Anyone know how to implement cross-browser username/password autocomplete in GWT (specifically GXT)?
Use persistent Cookies instead.
IE do save passwords, if user chooses to, but it works different. You need to type at least the username so it will autocomplete the password.
You need a plain vanilla html submit button. I think that will fix it.
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/2b2ce0b6aaa82461

How to open a new window on form submit

I have a submit form and want it to open a new window when users submits the form so i can track it on analytics.
Here is the code I'm using:
<form action="http://URL at mailchimp subscriber URL.com" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" onclick=window.open(google.html,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');>
<label for="name">Your Name</label><input type="text" value="" name="FNAME" class="required" id="mce-FNAME">
<br/>
<br/>
<label for="email">Your Email </label><input type="text" value="" name="EMAIL" class="required email" id="mce-EMAIL">
<br/>
<br/>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="submit">
</form>
</div>
No need for Javascript, you just have to add a target="_blank" attribute in your form tag.
<form target="_blank" action="http://example.com"
method="post" id="mc-embedded-subscribe-form"
name="mc-embedded-subscribe-form" class="validate"
>
In a web-based database application that uses a pop-up window to display print-outs of database data, this worked well enough for our needs (tested in Chrome 48):
<form method="post"
target="print_popup"
action="/myFormProcessorInNewWindow.aspx"
onsubmit="window.open('about:blank','print_popup','width=1000,height=800');">
The trick is to match the target attribute on the <form> tag with the second argument in the window.open call in the onsubmit handler.
For a similar effect to form's target attribute, you can also use the formtarget attribute of input[type="submit]" or button[type="submit"].
From MDN:
...this attribute is a name or keyword indicating where to display the response that is received after submitting the form. This is a name of, or keyword for, a browsing context (for example, tab, window, or inline frame). If this attribute is specified, it overrides the target attribute of the elements's form owner. The following keywords have special meanings:
_self: Load the response into the same browsing context as the current one. This value is the default if the attribute is not specified.
_blank: Load the response into a new unnamed browsing context.
_parent: Load the response into the parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.
_top: Load the response into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self.
onclick may not be the best event to attach that action to. Anytime anyone clicks anywhere in the form, it will open the window.
<form action="..." ...
onsubmit="window.open('google.html', '_blank', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');return true;">
The code you have given, needs to be corrected. In form tag you have to enclosed the onClick attribute value in double quote:
"window.open('google.htm','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');"
You also need to take care that first parameter of window.open should also be enclosed using quotes.
I generally use a small jQuery snippet globally to open any external links in a new tab / window. I've added the selector for a form for my own site and it works fine so far:
// URL target
$('a[href*="//"]:not([href*="'+ location.hostname +'"]),form[action*="//"]:not([href*="'+ location.hostname +'"]').attr('target','_blank');
i believe this jquery work for you well please check a code below.
this will make your submit action works and open a link in new tab whether you want to open action url again or a new link
jQuery('form').on('submit',function(e){
setTimeout(function () { window.open('https://www.google.com','_blank');}, 1000);});})
This code works for me perfect..
window.open doesn't work across all browsers, Google it and you will find a way of detecting the correct dialog type.
Also, move the onclick call to the input button for it to only fire when the user submits.