Checking username duplicates

There was an annoying issue with the old version of the user creation screen.  The system automatically creates a username when you enter the first name/last name fields.  It always follows the ‘lastnamefirstinitial’ format.  However, usernames must be unique in the system (at least, within that site’s record), so if you tried to save an account with an identical username, you’d get an errror.

What’s worse, there would be no warning- you’d just get a full refresh of the form, lose all your entered data, and have to start again.

So I set up an ajax function to check the username against those in the db for that site’s record.  If it finds a match, it will add another letter from the first name to the username (lastname + first 2 initials).  That way, we can keep a very similar format and eliminate some admin frustration.

I’m not sure how most devs do it, but my main method of testing for this was logging everything to the console.  The data I passed to my php page, the response it gave me, etc.  When I had it matched up right, I just pulled the log calls and it was good to go.  I’m betting there’s a better way to do this, but it works for now.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s