Jump to content
stormy

Filter out from domain search: www, slashes, http, etc.

Recommended Posts

Put this code in the bottom of domainregister.tpl to get rid of any extraneous stuff that customers will type into a domain search: "www.", slashes, https, spaces, etc.

By the way, this also solves a bug I've reported, where searching for a domain with "www.", like "www.thedomainiwant.com" will return "www.com is unavailable".

<script>
  jQuery('#frmDomainChecker').submit(function() {
      var domain = jQuery('input[name="domain"]').val();
      domain = domain.replace("www.", "");
      domain = domain.replace("http://", "");
      domain = domain.replace("https://", "");
      domain = domain.replace(" ", "");
      domain = domain.replace("/", "");
      domain = domain.toLowerCase();
      jQuery('input[name="domain"]').val(domain);
      return true;
  });
</script>

 

Edited by stormy

Share this post


Link to post
Share on other sites
1 hour ago, stormy said:

Put this code in the bottom of domainregister.tpl to get rid of any extraneous stuff that customers will type into a domain search: "www.", slashes, https, spaces, etc.

which as a hook would be...

<?php

# Domain Search Filter Hook
# Originally written by stormy
# Hooked by brian!

function domain_search_filter_hook($vars) {
	
	if ($vars['templatefile'] == "domainregister") {
	
	return <<<EOF
	<script>
  jQuery('#frmDomainChecker').submit(function() {
      var domain = jQuery('input[name="domain"]').val();
      domain = domain.replace("www.", "");
      domain = domain.replace("http://", "");
      domain = domain.replace("https://", "");
      domain = domain.replace(" ", "");
      domain = domain.replace("/", "");
      domain = domain.toLowerCase();
      jQuery('input[name="domain"]').val(domain);
      return true;
  });
</script>
EOF;
	}
};
add_hook("ClientAreaFooterOutput",1,"domain_search_filter_hook");
  • Thanks 2

Share this post


Link to post
Share on other sites

Awesome! Is there any advantage of the hook over editing the template? Besides not needing to edit the template, of course 🙂

Edited by stormy

Share this post


Link to post
Share on other sites
3 hours ago, stormy said:

Awesome! Is there any advantage of the hook over editing the template? Besides not needing to edit the template, of course 🙂

not needing to edit the template would be the main selling point of using the hook... of course, if you've already made changes to the template, then it's not strictly necessary, but if this is the only (non-CSS) change a user wants to make to their domain registration page, then it would make sense to use a hook.

  • Thanks 1

Share this post


Link to post
Share on other sites
10 minutes ago, brian! said:

not needing to edit the template would be the main selling point of using the hook... of course, if you've already made changes to the template, then it's not strictly necessary, but if this is the only (non-CSS) change a user wants to make to their domain registration page, then it would make sense to use a hook.

Can not this customization work for the correct homepage? http://prntscr.com/lo6a2d

I even removed the conditional from the template.

 

Share this post


Link to post
Share on other sites
5 minutes ago, edvancombr said:

Can not this customization work for the correct homepage? http://prntscr.com/lo6a2d

does it need to?

C62iEgC.png

click the search button, and the current hook modifies the search term...

8d7EUAu.png

unless you're telling me otherwise, I don't see the need to expand it for the homepage.

Share this post


Link to post
Share on other sites
2 minutes ago, brian! said:

click the search button, and the current hook modifies the search term...

There's another reason for using the hook instead of modifying the template!

Share this post


Link to post
Share on other sites
4 minutes ago, brian! said:

does it need to?

C62iEgC.png

click the search button, and the current hook modifies the search term...

8d7EUAu.png

unless you're telling me otherwise, I don't see the need to expand it for the homepage.

You are right!

I had removed the hook.

Share this post


Link to post
Share on other sites
2 minutes ago, stormy said:

There's another reason for using the hook instead of modifying the template!

i'd imagine it would do the same with your original template edit too - though I didn't try it.

Share this post


Link to post
Share on other sites
1 minute ago, brian! said:

i'd imagine it would do the same with your original template edit too - though I didn't try it.

Not if you use external forms that post to the domain search. So this is the better option overall!!!

Share this post


Link to post
Share on other sites
3 minutes ago, stormy said:

Not if you use external forms that post to the domain search.

it would work if you put your template code in footer.tpl rather than domainregister.tpl - as that's basically all this hook is doing anyway.

Share this post


Link to post
Share on other sites

Ah, I didn't look at the "ClientAreaFooterOutput" part.

By the way, I've added to this hook another useful snippet to filter question marks from knowledgebase searches:

jQuery('#kbsearch').submit(function() {
    var search = jQuery('#kbsearch input[name="search"]').val();
    search = search.replace(/\?/g, "");
    search = search.replace(/\¿/g, "");
    jQuery('#kbsearch input[name="search"]').val(search);
    return true;
});

Customers will frequently use question marks and they get less search results because they are used in the actual search.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines