Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Capitalise First Letters in Customer Info

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-22-2004, 10:31 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Capitalise First Letters in Customer Info

v3.5.*

This mod makes the customer data neater, by capitalising the first letters of the data entered and saves you editing it later.

joe bloggs becomes Joe Bloggs

1) Make a file called capitalise.js and shove it in the skin1 directory.

Add this code to it...

Code:
//////////////////////////////////////////////////////////////////////// //Capitalise the first letter in a textbox once the value is changed //Call as follows onChange="Proper(this); return true;" function Proper(o) { var s = o.value; var out = ""; if (s.length > 0) { var c = true; // process each character one at a time for (var i=0; i < s.length; i++) { var t = s.substring(i,i+1).toUpperCase(); // if not alpha cap next character cmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ'"; if ( cmp.indexOf(t) < 0) { c = true; } else { if (c) { c = false; } else { t = t.toLowerCase(); } } // take special cases like Mc and Mac and Roman numerals if ( i > 1 ) { temp = s.substring(i-2,i).toUpperCase(); if ( temp == "MC" ) { t = t.toUpperCase(); } cmp = " II V X"; roman = "IVX"; roman2 = "IVX "; if ( cmp.indexOf(temp) >= 0 && roman.indexOf(t.toUpperCase()) >= 0 && roman2.indexOf(s.substring(i+1,i+2).toUpperCase() ) >= 0 ) { t = t.toUpperCase(); } } if ( i > 2 ) { temp = s.substring(i-3,i).toUpperCase(); if ( temp == "MAC") { t = t.toUpperCase(); } if ( ( temp == " XI" || temp == " VI" || temp == " XX" || temp == "XV" ) && ( t.toUpperCase() == "I" || t.toUpperCase() == "V" || t.toUpperCase() == "X" ) ) { t = t.toUpperCase(); } } out += t; } o.value = out; } return true; }


2) Then find xcart/skin1/customer/home.tpl

Add this code between <head> and </head>

Code:
<script language=JavaScript1.3 src="{$SkinDir}/capitalise.js"></script>


3) Then locate the following templates in the xcart/skin1/main directory

register_billing_address.tpl
register_shipping_address.tpl
register_personal_info.tpl
states.tpl (only if you have the states field as an input field)

see also
xcart/skin1/help/contactus.tpl
if you want to use it on the 'contact us' form

Call the script by adding this code to the input fields:

Code:
onChange="Proper(this); return true;"

eg.

Change

Code:
<input type=text name=b_firstname size=32 maxlength=32 value="{$userinfo.b_firstname}">

to

Code:
<input type=text name=b_firstname size=32 maxlength=32 value="{$userinfo.b_firstname}" onChange="Proper(this); return true;">

etc.

Hope someone finds this useful.

See also a method for capitalising the zip/postal code

http://forum.x-cart.com/viewtopic.php?t=8112
Reply With Quote
  #2  
Old 06-23-2004, 08:09 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Honestly, I could kiss you for this.

90% of my customers are kids and lack of proper capitalisation is a MAJOR pet peeve of mine.

The L33T speak is bad enough, but when the names and addresses are jumbled... ARGH!

Cool Mod, I'll test it in my new store this weekend.
Reply With Quote
  #3  
Old 06-24-2004, 07:16 AM
 
GM GM is offline
 

eXpert
  
Join Date: Mar 2004
Location: Canada
Posts: 293
 

Default

Nice one PhilJ
__________________
v. 4.0.14 (GM Style)
O.S. Linux
Build Your Own Diamond Ring
Reply With Quote
  #4  
Old 10-30-2004, 04:30 PM
 
chawla@moviesandgamesonli chawla@moviesandgamesonli is offline
 

Senior Member
  
Join Date: Mar 2003
Location: UK
Posts: 125
 

Default

Works fine in Version 4.0.6, but how do I get the Post Code all in capitals, instead of the first letter only.

Version 4.0.6
Reply With Quote
  #5  
Old 10-30-2004, 04:35 PM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default

check this post to capitalise post code

http://forum.x-cart.com/viewtopic.php?t=8112
__________________
xcartmods.co.uk
Reply With Quote
  #6  
Old 11-24-2004, 06:03 PM
 
Metal-X-Man Metal-X-Man is offline
 

eXpert
  
Join Date: Mar 2003
Location: Columbus, Ohio
Posts: 204
 

Default

Thanks Phil! It's been driving me crazy for years, always correcting the users input. Thanks again!

Metal-X
Reply With Quote
  #7  
Old 12-08-2004, 05:54 AM
 
zefon zefon is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 86
 

Default

Very cool mod. It makes everything look much more professional when the type is consistent.

I installed this mod. It works great on the contact us form and the new user register form. However it is not working during order checkout for new users. I have Jon's Easy Checkout mod installed and I suspect there might be some conflict with some other script in the files but don't know how to go about troubleshooting it. When you load the page, all is fine with no errors. Once you type data into a field and move to the next field, the yellow error triangle shows on the lower left corner of the browser.

Also, anyone know SQL code to now go back and fix all the names in the database?
__________________
X-Cart Gold 4.1.8
Reply With Quote
  #8  
Old 12-08-2004, 06:00 AM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Make sure you are including the JS in the home_checkout.tpl (EZ Checkout) as well as home.tpl.
Reply With Quote
  #9  
Old 12-08-2004, 06:12 AM
 
zefon zefon is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 86
 

Default

Thanks adpboss. I got it working. I had the script in home_checkout.tpl, but moved the location of it within the <head> tag and that fixed it.

Very cool to have this working now.
__________________
X-Cart Gold 4.1.8
Reply With Quote
  #10  
Old 12-17-2004, 05:15 AM
 
zefon zefon is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 86
 

Default

For those of you who want to update your existing database, you can use the following SQL query:

Code:
UPDATE xcart_customers SET firstname = CONCAT(UPPER(SUBSTRING(firstname,1,1)),SUBSTRING(firstname,2,LENGTH(firstname)-1));
Just replace "firstname" with the field you want to change. I got this code from x-cart and it works on all the one word fields. I have not figured out how to do the address line though. If anyone else know that one, please share.
__________________
X-Cart Gold 4.1.8
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:14 PM.

   

 
X-Cart forums © 2001-2020