Welcome to the herd.

This is our Herd Speak!

We are Hippo - a talkative agency.

At Hippo, we love to talk - and where better in this digital age to talk than in our very own herd speak?


ClientSide Username Checking, EE and jQuery

Posted 27th Jul by Carl Crawley

One of the other jobs needed for our last project was an ‘auto-check’ function whereby we could tell a user whether their chosen username was available or not *before* they signed up.

To do this, I simply used a custom/hidden template group/file, the tag and jQuery to pull it all together.

Firstly, you need to create yourself a new template group / file. These suggestions are purely for examples, you can call them what you want:

  • Template Group “_ajax”
  • Template File “username_check”

Ok – now that you have them, open the username_check template and enter the following:

{exp:query sql="select username from exp_members where username = '{segment_3}'"}
{username}
{/exp:query}

Note: If you have a multi-lingual set up like my previous post on Multilingual sites in EE, then you will need to change for .

To test your setup, you can simply now visit http://www.yoursite.com/_ajax/username_check/ and if a user exists it should return you the username else it will return a blank page.

(I had thought about turning the returned data into a JSON or XML response with more details, however this would then be open to misuse – so decided against it).

Now for the jQuery Implementation:

Firstly, create your input field and a container to handle your returned messages:

<input type="text" name="username" id="frm_username" value="" /> <p class="username_return"></p>

Then, either in the <head> or in a js file – simply put the following:

$(document).ready(function(){
$("#frm_username").keyup(function(){
$.ajax({
type: 'GET',
url: '/index.php/_ajax/username_check/'+$(this).val(),
success: function(data){
if (data=="")
{
$("p.username_return").html("Username Available")
$("p.username_return").css('background-color','#00ff00');}
else
{
$("p.username_return").html("Username Not Available, please choose another!")
$("p.username_return").css('background-color','#ff0000');
}
}
})
return false;
})
})

And thats it! You can extend this beyond the example here, for example, disable the submit button, change the colour of the input field, make the input field shake etc etc – the possibilities are endless!

Likewise, you can extend the script to check for anything you want – screen_name, email etc etc.


Comments (2)


It was an interesting add-on story to read. It looked like someone is telling waterhouse friderichsen syndrome
my own story. Sometimes, when we stuck somewhere or get in to some kind of bugs, it’s very difficult to come out.

Posted 19-01-12 by waterhouse friderichsen syndrome


The problem with that, however, is relying on splitting the value at the @. What if the field you’re checking doesn’t have an email address for content, but something Monster Galaxy else that EE blocks? Say, if you’re checking the user’s desired screen name (which apparently has to be unique unless you hack the core files), and a user wants the screen name “Dr. M’Benga”, you run into problems with the apostrophe (and possibly the space as well).

Posted 22-01-12 by Andy


Comment page 1 of 1 pages

Post a comment and leave your mark!

Hippo Projects


Seaview Residential Care Home

16th Aug

title

A small site designed and developed for a local residential care home. Full content management system with multiple user access and editable regions.


LibrarEE

13th Dec

title

Sales and Marketing site for 'LibrarEE' an ExpressionEngine Module built in collaboration with Nico De Gols.

Some of our clients past and present

  • Orionesque
  • FireIsland
  • Pinkeye Graphics LTD
  • Slipstream Studio
  • OC Group
  • Wight Coast and Country Cottages

Testimonials

Carl's creativity and in-depth technical knowledge combined with his high energy and enthusiastic approach to our requests and requirements made working with…»

Ruari Chisholm, Director, High Performance Development LTD

Hire us for your next project

From a simple consultancy role to a complete custom build - why not get in touch and see how Hippo can help you with your next project.