Vacman |
05-17-2013 02:00 PM |
Upper Case (Checkout Page) for 4.5.x
If you are running 4.5.5 (and I am assuming 4.5.4) and don't like the fact that lazy people don't know how to use caps properly and format a telephone number correctly, I with the help of another good friend have figured out how to make this work.
1. In your skin/customer/home.tpl you will add the following code before the </head>
Code:
{literal}
<script>
function ValidatePhone(elem) {
var pn = elem.value;
if (pn == "") return;
pn = pn.replace(/\D/g,"");
if (pn.length == 7)
elem.value = pn.replace(/(\d{3})(\d{4})/,"$1-$2");
else if (pn.length == 10)
elem.value = pn.replace(/(\d{3})(\d{3})(\d{4})/,"($1) $2-$3");
else {
alert('The '+elem.name+' must be a 7 or 10 digit phone number');
elem.focus();
return false;
}
}
</script>
<script type="text/javascript">
String.prototype.toTitleCase = function() {
var words = this.split(" ");
for(var i = 0; i < words.length; ++i)
words[i] = words[i].charAt(0).toUpperCase() + words[i].substring(1).toLowerCase();
return words.join(" ");
};
</script>
{/literal}
2. In your skin/common_files/One_Page_Checkout/profile/address_fields.tpl add the following code around line #61 just after the line where it says default_city.
Code:
{elseif $fname eq 'phone'}
<input type="text" id="{$id_prefix}{$fname}" name="{$name_prefix}[{$fname}]" size="32" maxlength="255" value="{$address.$fname|escape}" OnBlur="ValidatePhone(this)" />
{else}
<input type="text" id="{$id_prefix}{$fname}" name="{$name_prefix}[{$fname}]" size="32" maxlength="255" value="{$address.$fname|escape}" onBlur="this.value = this.value.toTitleCase();" />
|