In some forms, Chrome autofill prompts with Credit card autofill.
EDIT:Adding screenshot. This is not the same as browser autocomplete. You need not have entered the value in the same form before.
How should I write my HTML form so the browser detects these as Credit card fields and triggers this behavior?
An example of it working with a Stripe form would be ideal.
The “Settings” tab will open. Click “Autofill” in the sidebar, then select “Payment Methods.” Under Payment Methods settings, look for a subsection also called “Payment Methods” near the bottom of the window. If Chrome has previously saved any credit cards, they will be listed here.
When you enter info in a new form online, Chrome might ask you if you'd like Chrome to save it. Chrome never shares your info without your permission. Learn how Google Chrome saves and protects credit card information. If you would like to save your password info to Chrome, learn how to manage saved passwords.
Open Chrome, tap on the three dots and go to Settings, followed by Payment methods. Any previous payment methods you added will show up here. If you only want to disable the feature and not remove any credit card information, toggle the feature off.
Chrome isn't a credit card vendor. I can save your credit card number for you too, if you want. The CCV check Chrome does doesn't compare the entered CCV against anything stored at all. Instead, it charges a small amount to verify the credit card.
This question is pretty old but I have an updated answer for 2019!
You can now tell your browser which fields are for credit card info just by naming the <input>
correctly.
The following answer is from my original answer from here: https://stackoverflow.com/a/41965106/1696153
Here's a link to the official current WHATWG HTML Standard for enabling autocomplete.
Google wrote a pretty nice guide for developing web applications that are friendly for mobile devices. They have a section on how to name the inputs on forms to easily use auto-fill. Eventhough it's written for mobile, this applies for both desktop and mobile!
Here are some key points on how to enable autocomplete:
<label>
for all your <input>
fieldsautocomplete
attribute to your <input>
tags and fill it in using this guide.name
and autocomplete
attributes correctly for all <input>
tagsExample:
<label for="frmNameA">Name</label> <input type="text" name="name" id="frmNameA" placeholder="Full name" required autocomplete="name"> <label for="frmEmailA">Email</label> <input type="email" name="email" id="frmEmailA" placeholder="[email protected]" required autocomplete="email"> <!-- note that "emailC" will not be autocompleted --> <label for="frmEmailC">Confirm Email</label> <input type="email" name="emailC" id="frmEmailC" placeholder="[email protected]" required autocomplete="email"> <label for="frmPhoneNumA">Phone</label> <input type="tel" name="phone" id="frmPhoneNumA" placeholder="+1-555-555-1212" required autocomplete="tel">
<input>
tagsIn order to trigger autocomplete, make sure you correctly name the name
and autocomplete
attributes in your <input>
tags. This will automatically allow for autocomplete on forms. Make sure also to have a <label>
! This information can also be found here.
Here's how to name your inputs:
name
: name fname mname lname
autocomplete
: name
(for full name)given-name
(for first name)additional-name
(for middle name)family-name
(for last name)<input type="text" name="fname" autocomplete="given-name">
name
: email
autocomplete
: email
<input type="text" name="email" autocomplete="email">
name
: address city region province state zip zip2 postal country
autocomplete
: street-address
address-line1
address-line2
address-level1
(state or province)address-level2
(city)postal-code
(zip code)country
name
: phone mobile country-code area-code exchange suffix ext
autocomplete
: tel
name
: ccname cardnumber cvc ccmonth ccyear exp-date card-type
autocomplete
: cc-name
cc-number
cc-csc
cc-exp-month
cc-exp-year
cc-exp
cc-type
name
: username
autocomplete
: username
name
: password
autocomplete
: current-password
(for sign-in forms)new-password
(for sign-up and password-change forms)From this answer https://stackoverflow.com/a/9795126/292060, it looks like Chrome is either matching a regex pattern on the field name, or the form is explicitly using the x-autocompletetype
attribute, like this (This example uses "somename" to avoid mixing issues matching on the name):
<input type="text" name="somename" x-autocompletetype="cc-number" />
Practically, you could do both, picking a name that matches, and the x-autocompletetype:
<input type="text" name="ccnum" x-autocompletetype="cc-number" />
Do you have a view-source of the input box in your screenshot? That would show if it's matching on the name or on the x-autocompletetype attribute.
The answer I linked to has several links for more information; I didn't repeat them here.
Some other comments:
I know Chrome pops a question whether to save the credit card information (I don't), but I don't know if it is popping that question regardless of how it detected it. That is, I'm not sure if Chrome will autocomplete separate fields of credit cards along with other fields, or if it needs to save the whole thing as a credit card.
Your question was how to do it, not whether to. But from the comment in your question, I agree that you might not want to autocomplete the credit card fields. Personally I find it disconcerting when it happens, even knowing it's local in my browser (I especially feel this way about the CVV, and get a surprising amount of resistance when I report it). However, there are posts that find it frustrating when a customer wants to use it, has Chrome set up with credit cards, and a website blocks it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With