Jump to content

trivial issue in domain search box


Remitur

Recommended Posts

I've just realized that the standard domain search box (the one most of us have in home page, "find your domain name" - "register or transfer" and so on) has a trivial issue.

If the user is smart, and inputs

thisismydomain.com

everything is right.

But if the user is not so smart (and users are NEVER smart...), and he inputs

www.thisismydomain.com

WHMCS will answer that "the domain is not avaialable.

If would be a good (and easy to do) thing to strip away from what inserted by the user:

  • leading "http://" (if present)
  • leading "https://" (if present)
  • leading "www." (if present)

 

 

 

Link to comment
Share on other sites

17 hours ago, Remitur said:

If would be a good (and easy to do) thing to strip away from what inserted by the user:

  • leading "http://" (if present)
  • leading "https://" (if present)
  • leading "www." (if present)

if it's easy to do, why don't you tell the rest of us how to solve it! :P

one option would be to use a HTML5 pattern to prevent the above terms being submitted...

another method would be to use a combination of js via an action hook, and then with a template edit to call it - this would allow the term to be entered, but then changed before beginning the search...

firstly the hook - this adds the js code to the <head> section of the template (but only on the domainregister page) - i've kept the js simple with 3 basic replaces for now, but you could use other methods if you had to...

<?php

/**
* Add Domain Validation To Domain Registration Page
* @author brian!
*/

add_hook('ClientAreaHeadOutput', 1, function($vars) {
    
	$templatefile = $vars['templatefile'];
	if ($templatefile == "domainregister") {
		
		return <<<HTML
	<script>
		function DomainValidation(){
			str = document.domcheck.domain.value;
			res = str.replace("https://", "").replace("http://", "");
			if (res.substring(0, 4) == "www.") {
				res = res.replace("www.", "");
			}
			document.domcheck.domain.value = res;
			document.getElementById("domcheck").submit();
		}
	</script>
HTML;
}
});

and then in domainregister.tpl, you would change...

<form method="post" action="cart.php" id="frmDomainChecker" />

to...

<form method="post" action="cart.php" id="frmDomainChecker" name="domcheck" onsubmit="DomainValidation();">

OCFUGRl.png

FHHtPK3.png

https://www.screencast.com/t/XDxmGTU5pg

this will also work on the domain checker page directly too. :idea:

however, it's worth noting that this method would fail if the user just entered 'www.*TLD*' (e.g www.com) as a search term because it would strip the 'www.' out and just leave 'com'... but as 'www' is an ICANN reserved word anyway, the chances of the user ever being able to register www.*TLD* is virtually nil I would have thought... 'wwwww.google.com' would fail to be changed too.

now I suppose you could code around that if you felt so inclined, but I wouldn't see any obviously simple (and foolproof!) way to do it... for example, 'wwwww.whmcs.com' would be invalid... yet 'wwwww.co.uk' would be fine... it gives me a headache just thinking about it! :67_head_bandage:

Link to comment
Share on other sites

Both solutions are nice and... "elegant"!   

7 hours ago, brian! said:

another method would be to use a combination of js via an action hook, and then with a template edit to call it - this would allow the term to be entered, but then changed before beginning the search...

Just a question: the hook code need to be inserted as usual in /includes/hooks , or elsewhere?

Link to comment
Share on other sites

12 hours ago, Remitur said:

Just a question: the hook code need to be inserted as usual in /includes/hooks , or elsewhere?

yes the usual place - /include/hooks - give it a .php filename, copy&paste the code into it, tweak the template as described and you should be good to go. :idea:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • 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