Jump to content

How To force lowercase domain names on orderform


tsiedsma

Recommended Posts

I have noticed an increase in orders with upper case letters in domain names like this: ThisTypeOFDomain.com

 

Why is this a problem you ask? Well, WHMCS does not force it to be lower case, this results in the username for cPanel to be uppercase and lowercase. cPanel runs on Linux which is case sensitive. Also, domains are all lower case, so why not just force it from the start?

 

Here is my solution. I have made a couple of assumptions here, you need to have jQuery and the order form is the first form on your page. If you have any other forms that exist on your page, there are ways to make this work easier.

 

Paste this code at the very top of configureproductdomain.tpl in your whmcs/templates/orderforms/template folder

{literal}
<script type="text/javascript">
$(function() {
 $('form:first').submit(function() {
   $('input[type=text]').each(function() {
     $(this).val($(this).val().toLowerCase());
   });
 });
});
</script>
{/literal}

 

You can edit your template file and give your form an id like this:

<form method="post" action="{$smarty.server.PHP_SELF}?a=add&pid={$pid}" id="configProductForm">

Then edit the jquery code above and change the following:

$('form:first').submit(function() {

to

$('#configProductForm').submit(function() {

 

This will ensure the submit function is bound to the proper form.

 

What does this do? When the user types in UpPeRCase letters into the domain fields, as soon as the form is submitted they are changed to lower case. This will be evident on the following pages.

 

Post here if you have any issues or questions!

 

Mod, can you move this to the How To's forum? I couldn't post a new thread!

Link to comment
Share on other sites

I will likely come up with a HOOK to fix this too. Then it is forced on the back end and the customer can't get around it. The other problem with jQuery is it requires javascript to be enabled on the customer's computer which we have no control over.

Link to comment
Share on other sites

I will likely come up with a HOOK to fix this too. Then it is forced on the back end and the customer can't get around it. The other problem with jQuery is it requires javascript to be enabled on the customer's computer which we have no control over.

 

congrats on looking for a solution - and yes, doing it by hook in your code, rather than javascript in the client-browser would be a better option.

Link to comment
Share on other sites

I just whipped this up and tested it myself.

 

Create a new file in whmcs/includes/hooks/ and call it whatever you want, or add this code to a file in that folder.

function lowercase_domain_hook($vars) {
 if (is_array($vars['products'])) {
   foreach($vars['products'] AS $k => $v) {
     if (isset($_SESSION['cart']['products'][$k]['domain'])) {
       $_SESSION['cart']['products'][$k]['domain'] = strtolower($v['domain']);
     }
   }
 }
 if (is_array($vars['domains'])) {
   foreach($vars['domains'] AS $k => $v) {
     if (isset($_SESSION['cart']['domains'][$k]['domain'])) {
       $_SESSION['cart']['domains'][$k]['domain'] = strtolower($v['domain']);
     }
   }
 }
}
add_hook("PreCalculateCartTotals",1,"lowercase_domain_hook");

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated