View Single Post
  #1  
Old 11-29-2006, 11:09 AM
 
sstillwell@aerostich.com sstillwell@aerostich.com is offline
 

eXpert
  
Join Date: Jun 2004
Location: Duluth, MN
Posts: 242
 

Default User Friendly Credit Card Field Mod

In his book "Don't Make Me Think" by Steve Krug (go read it), he states things that Diminish the Good Will of our customers.

"Punishing me for not doing things your way. I should never have to think about formatting data: whether or not to put dashes in my Social Security number, spaces in my credit card number, or parentheses in my phone number. Many sites perversely insist on no spaces in credit card numbers, when the spaces actually make it much easier to get the number right. Don't make me jump through hoops just because you don't want to write a little bit of code."

So, in the default Xcart install, the credit card field has these words.

Credit card number (no spaces or dashes)

Why don't we just implement some Javascript that strips out the none numbers when they try to submit. EASY.

Obligatory Disclaimers
1. I am using Credit Card verification, I don't think this will work without enabling that.
2. I use 4.0.12, it may be fixed in a new version.
3. This could completely destroy your Xcart store (but probably not).

Ready?

Open skin1/check_cc_number_script.tpl

Change this code
Code:
function checkCCNumber(field_cc,field_accepted) { var cc=field_cc.value; var accepted=null; if(field_accepted!=null) accepted=new Array(card_types[field_accepted.value]); if (isCreditCard(cc,accepted)) return true; else { alert(txt_cc_number_invalid); field_cc.focus(); field_cc.select(); return false; } }

To this code
Code:
function checkCCNumber(field_cc,field_accepted) { var original_cc=field_cc.value; var cc=field_cc.value.replace(/[^\d]/g, ''); var accepted=null; if(field_accepted!=null) accepted=new Array(card_types[field_accepted.value]); if (isCreditCard(cc,accepted)){ field_cc.value = cc; return true; }else { alert(txt_cc_number_invalid); field_cc.focus(); field_cc.select(); return false; } }

Basically, this just strips out the none numbers from the Credit card number and then if it passes the check, writes it back to the Credit Card input field before proceeding to submit the form.

Man that was easy.
__________________
No longer using Xcart, was good while it lasted.
Reply With Quote