View Full Version : AJAX: check if username exists on registration in realtime
MrNase
05-14-2005, 10:00 PM
It will be ported to vB 3.5 :)
The instructions are up-to-date (see post #8 for more information).
Hello there!
vB 3.5 is using AJAX for inline moderation and stuff like that. Pretty neat and why should we wait for something like this? :devious:
What does this hack do?
In the registration page it checks if the username the user has entered already exists. If this is true he will get a message instantly telling me to change the desired name. The submit button will also be disabled so that he can't finish the registration unless he has chosen another username which is not yet taken.
Features:
* can be turned off or on via the AdminCP
* uses the vB phrases and can easily be translated
* the user gets the error message without reloading the page
* he/she can't complete the registration if the username is taken
Do I need to be an expert to install this hack?
No, not really.. You have to upload two files, edit one file, edit one template and add some custom CSS. Besides this there are 4 queries you need to run (see the point 'Warning:' for more information). Should be pretty easy and I'll support you as good as I can.
Demo:
You may take this for a test drive at my forums but please don't complete the registration unless you want to join my german community ;)
http://www.pagodentreff.de/diskussionsforum/register.php
Just use 'dominik.h' as a username and see what happens.
Problems?
Is the new phrase not showing up? Read this: https://vborg.vbsupport.ru/showpost.php?p=654215&postcount=19
Warning:
This hack doesn't have an automatic installer. However you need to run 4 different queries for this hack to work. Those queries are for the settings in your AdminCP and for the phrases only. This hack won't affect your performance :)
If you feel uncomfortable with running queries you may drop me a private message and I'll see what I can do for you.
I will support this hack as good as I can but please keep your questions within this thread.
Please don't forget to click install (https://vborg.vbsupport.ru/vborg_miscactions.php?do=installhack&threadid=81531) because you get an update notification and other nice things ;)
The screenshot is taken from my translated version.
This hack wouldn't be possible without the following article and the code: http://www.xml.com/pub/a/2005/02/09/xml-http-request.html
Princeton
05-15-2005, 06:32 PM
it looks great! I'm gonna try this out. :D
nexialys
05-15-2005, 06:47 PM
/me was looking to code this same kind of ajax... great MRNase
MrNase
05-15-2005, 06:53 PM
hehe ;)
Please test it before you make it HOTM :D It worked for me and hopefully it'll work for you.
Dean C
05-15-2005, 07:06 PM
You might want to credit xml.com for the AJAX JS code :)
nexialys
05-15-2005, 07:07 PM
INSERT INTO `phrase` (`phraseid`, `languageid`, `varname`, `text`, `phrasetypeid`) VALUES (NULL, '0', 'registererror', 'The username you have chosen is already taken', '5000', '39'); have an error, have to drop the '5000', in it...
EDIT: btw, would be good to duplicate this process for the change username in profile... ;)
MrNase
05-15-2005, 07:13 PM
INSERT INTO `phrase` (`phraseid`, `languageid`, `varname`, `text`, `phrasetypeid`) VALUES (NULL, '0', 'registererror', 'The username you have chosen is already taken', '5000', '39'); have an error, have to drop the '5000', in it...
I changed it to:
INSERT INTO `phrase` (`phraseid`, `languageid`, `varname`, `text`, `phrasetypeid`) VALUES (NULL, '0', 'registererror', 'The username you have chosen is already taken', '', '39');
Dean C: Ok, I did that. This was my first static try http://validhtml.com/xmlhttprequest/. I just took the code from it without thinking much about it's source :nervous:
nexialys: That's a good idea.. Iam going to sleep now but I'll keep that in mind for tomorrow :)
Princeton
05-15-2005, 07:20 PM
MrNase,
I believe it should be:
INSERT INTO `phrase` (`phraseid`, `languageid`, `varname`, `text`, `phrasetypeid`) VALUES (NULL, '0', 'registererror', 'The username you have chosen is already taken', '39');
Princeton
05-15-2005, 07:22 PM
oh, by the way -- great hack/find. :up:
There's a lot we can do with this. ;D
MrNase
05-15-2005, 07:25 PM
Have you installed it and does it work for you?
I fixed the small error in the downloadable file.. It happened because I added the , '39' without thinking about the number of the affected rows (I tried to modify 6 where there are only 5 ;)).
I added all phrases and settings manually so I couldn't test them. I hope they are working for you :rambo:
Princeton
05-15-2005, 07:29 PM
yes, I installed it and it works as advertised.
I did run into the error but that was an easy fix. :)
Link14716
05-15-2005, 07:30 PM
I have no use for this without a community of my own, but I'll click install anyways since it looks like a nice hack. Good job. :)
Guest190829
05-15-2005, 07:37 PM
Oh very nice! I will test this out for you. :)
CompuJonathan
05-15-2005, 07:40 PM
Ok, I'm pretty sure I followed the instructions 100%...but for some reason it will not display the text in the pink warning box.
Any clue what would cause this?
Thanks!
CompuJonathan
05-15-2005, 07:54 PM
Ok, I'm pretty sure it has something to do with the SQL query. I ran both the one in the .txt file and the one princeton posted. Not sure why it isn't working. :ermm:
nexialys
05-15-2005, 07:55 PM
@MrNase: what would be best is to filter the username the same way it is filtered when the usual registration process occurs, because for now, it's not deleting spaces and illegal characters... anyway, this is the only thing i think to enhance... (would add a error like: your username contain illegal characters, etc...)
may be a good thing to add when users can posts when as guests (where we can add a username, the script would verify if you have a known username, and if yes, display the password field to berify...) anyway, i'm highly into enhancements... lol
C.Birch
05-15-2005, 08:02 PM
works fine here :)
MrNase
05-15-2005, 08:28 PM
Ok, I'm pretty sure it has something to do with the SQL query. I ran both the one in the .txt file and the one princeton posted. Not sure why it isn't working. :ermm:
Please verify that the phrase 'registererror' exists. If not you may add it yourself. :)
You must add it to the phrase-group 'register' (default would be GLOBAL, just select 'register' when adding it) because otherwise it doesn't work.
The queries which are in the instruction is up-to-date. You don't need to run those which are suggested in this thread :)
nexialys: That would only work if the JS-code is modified because by now it can only return true or false. Let's see if vB 3.5 has it in by default. If not the chances are good Iam releasing a hack that uses more AJAX :)
Link14716
05-15-2005, 08:42 PM
If you are inserting phrases, you need to update the cache. Editing any phrase and then saving it without changing anything usually does the trick.
C.Birch
05-15-2005, 08:45 PM
Ok, I'm pretty sure I followed the instructions 100%...but for some reason it will not display the text in the pink warning box.
Any clue what would cause this?
Thanks!
i had the same error, it had installed it in the master copy and i had to add the text to the English (US) Translation box.
MrNase
05-15-2005, 08:47 PM
Same for me but it worked without filling out the translation box :)
Iam not quite sure about the way the phrases work but I think the content of the first box is used if there's no translation. If there's a translation it will be used.
FightRice.com
05-15-2005, 08:51 PM
I've got the same problem, But i'm getting this error
Runtime error, line 49
submit is null or not an object
MrNase
05-15-2005, 08:54 PM
open the template register and search for:
<input type="submit" class="button" value="$vbphrase[complete_registration]" accesskey="s" />
replace it with:
<input type="submit" class="button" value="$vbphrase[complete_registration]" accesskey="s" name="submitform" />
The instructions are up-to-date :)
FightRice.com
05-15-2005, 08:59 PM
Awesome, did the trick, sweet modification here
MrNase
05-15-2005, 09:00 PM
See if this one helps: https://vborg.vbsupport.ru/showpost.php?p=654215&postcount=19 :)
If not follow this:
https://vborg.vbsupport.ru/showpost.php?p=654204&postcount=18
FightRice.com
05-15-2005, 09:00 PM
Yes sir, thank you very much
MrNase
05-15-2005, 09:02 PM
No problem. Iam glad its working now :)
(nice site btw. :))
Oblivion Knight
05-15-2005, 09:15 PM
This is a really nice little modification you have here..
Installed flawlessly. :)
sabret00the
05-15-2005, 09:40 PM
nice work :)
Lionel
05-15-2005, 09:55 PM
One question: Will that prevent non java users from registering?
MrNase
05-15-2005, 09:58 PM
No, this is failsafe.. Users without JS will see the default 'username already taken'-message when they submit the form :)
Lionel
05-15-2005, 10:01 PM
Thanks for quick answer. Just came from your site. This is a really useful hack.
MrNase
05-15-2005, 10:08 PM
Don't expect a fast reply from me within the next few hours.. Iam going to explain my girlfriend what AJAX really does ;) :D
vB is some kind of illness.. Once I started coding and stuff only my girlfriend gets me to sleep :ermm:
T3MEDIA
05-15-2005, 10:53 PM
What does this do? Maybe its me I couldnt work the demo (english) but unless I am missing something when a user picks a name that is already on my site they get an error message. what is this for exactly? Sorry I am just not sure what this is for.
Princeton
05-15-2005, 10:55 PM
it will save the user's time when submitting the form ..
eg. if they know that the username is already taken they will likely change it before submitting it
T3MEDIA
05-15-2005, 11:01 PM
it will save the user's time when submitting the form ..
eg. if they know that the username is already taken they will likely change it before submitting itAhhhh nice action. Oh ok. that's nice...
You know what would be HOT if that worked for email as well.
myspace.com does this. (not the name) but the email address.
Ohhhh even better.
imagine it works with accounts you block as well?
say I block AOL in the admincp bob puts bob@aol.com it tells him in advance.
same for referals. if a user adds a referer and they dont exist the response is confusing for some. (try it) with this configured properly it could tell them that this user does not exist thus you cant use this name as a referer.
Hummm might as well huck up the registration page fully! its the hard close on the sell right?
If you guys do that... that would be insane.
Does this add aa query with every key press, then?
Princeton
05-15-2005, 11:15 PM
yes it does (for every username--key)
Lionel
05-16-2005, 12:01 AM
yes it does (for every username--key)
Is that bad if you have more than 6000 members?
Christine
05-16-2005, 12:02 AM
Well now, ain't this a beautiful thing!
Works great on 3.0.7
/me installs!
Sebastian
05-16-2005, 12:15 AM
cool hack... unfortunately i hate javascript with passion.. moreso, it doesn't work on all browsers which is the main reason i avoid it (javascript).
CompuJonathan
05-16-2005, 12:51 AM
Thanks guys, got it working now. I just deleted the phrase and re added it...didn't try doing the English translation. Great work, love it!
T3MEDIA has a great suggestion, it would be very cool if we could just jack the entire signup process with this, would save the users a lot of time when they make 1 simple error in the referral and ect.
Again, excellent!
- Jonathan
Works excellent!
/me clicks install
JulianD
05-16-2005, 02:15 AM
Great hack! :)
I made some modifications to your code, creating another php file (I don't need to load vB permissions and sessions just to check for the username) and modifying the javascript so it only checks the username if it's longer than 3 chars.
* JulianD clicks install!
dsboyce8624
05-16-2005, 03:28 AM
As somebody who has only been doing this for a couple weeks, I'd like to make a suggestion. Take it for what it's worth.
I've grown accustomed to very noticable markers in the instructions for file/template changes. Meaning when it's time to start editing a different document.
Yours is great, and the hack is great, but the first time through I added a whole lot of the instructions to the register.php file by accident.
Yes, I'm an idiot. But, THERE ARE LOTS OF US!
So to save yourself lots of extra posts, you might want to edit that a bit.
Dennis
MrNase
05-16-2005, 08:09 AM
Does this add aa query with every key press, then?
No it doesn't. It checks for the username when the user is done with typing in the username and proceeding to a new input field.
I would like to see how fast this one works with +20k members but it should not be that slow because it's just one simple query.
dsboyce8624: Thank you for this advice. I'll do so as soon as I got more time on my hands.. :bandit:
Marco van Herwaarden
05-16-2005, 08:58 AM
Try to edit ANY phrase using the normal ACP tooling. (just save it, no need for a real edit)
nexialys
05-16-2005, 09:15 AM
I would like to see how fast this one works with +20k members but it should not be that slow because it's just one simple query.for the ones that are asking, even if you have 20 000 users on your board, this process is not slower, and does not ask a lot of server power, because it's just reading one table WHEN someone register, not each time someone fill a form... your 20 000 members are not registering at the same moment... this is the same query that is called when someone login, or change his name, or send a pm, etc... please don't imagine strange behaviors when there is none...
MrNase
05-16-2005, 11:51 AM
It isn't you are right :)
But this script is checking wether a username exists or not. With +20k users it may take half a second before the person who registers is seeing that message :)
Christine
05-16-2005, 12:35 PM
I have right at 16,000 members and it took less than a nano-second when I tabbed off the field. This was with 300 users online at the time.
T3MEDIA
05-16-2005, 12:51 PM
Thanks guys, got it working now. I just deleted the phrase and re added it...didn't try doing the English translation. Great work, love it!
T3MEDIA has a great suggestion, it would be very cool if we could just jack the entire signup process with this, would save the users a lot of time when they make 1 simple error in the referral and ect.
Again, excellent!
- JonathanThink they will take me up on it? Its about 3 other fields using the same idea. You should ask for this mod though you may get a better response.
I have a site with 21k on it and it went a bit slow. (slow as in not just poping up instantly). you need to keep in mind the users online that are doing god knows what.... and this site had the arcade going on... resource monster. around 1g online prime time.
CompuJonathan
05-16-2005, 11:52 PM
T3,
Yeah, I'm not really sure how much extra work it would take to turn make that work for the password/email/referral field. But I hope it can be done and that they will do it for us! :o
I don't allow ASCII characters and other things on my forum, it would be too cool if it could tell them "No ASCII allowed" if they do use it.
Question: After a tab into a different filed on the sign up, an error comes up saying that 'submit' is null or not an object?
Thanks!
- Jonathan
Oblivion Knight
05-17-2005, 05:50 AM
Question: After a tab into a different filed on the sign up, an error comes up saying that 'submit' is null or not an object?This was fixed here:
https://vborg.vbsupport.ru/showpost.php?p=654227&postcount=23
:)
CompuJonathan
05-17-2005, 11:00 PM
This is the way I have mine, but I still get the submit error. :ermm:
<div style="margin-top:$stylevar[cellpadding]px"><input type="submit" class="button" value="$vbphrase[complete_registration]" accesskey="s" name="submitform" /><input type="reset" class="button" name="Reset" value="$vbphrase[reset_fields]" />
MrNase
05-18-2005, 03:49 AM
Can you pm me with the url to your forums please? :)
MrNase
05-18-2005, 08:55 AM
I checked your code three times and couldn't point out where the error was so here's another solution to this. I hope this one solves it.
open ajax_checkusername.js and replace:
submit = document.register.submitform;
with
submit = document.getElementById('submitform');
and change (in the template 'register') this:
<div style="margin-top:$stylevar[cellpadding]px"><input type="submit" class="button" value="$vbphrase[complete_registration]" accesskey="s" name="submitform" /><input type="reset" class="button" name="Reset" value="$vbphrase[reset_fields]" />
to this:
<div style="margin-top:$stylevar[cellpadding]px"><input type="submit" class="button" value="$vbphrase[complete_registration]" accesskey="s" id="submitform" /><input type="reset" class="button" name="Reset" value="$vbphrase[reset_fields]" />
Please try that and tell me if it's working :)
__________________________________________________ ___
Here's another solution that came up after some google searches.
Open ajax_checkusername.js and replace:
function checkName(input, response)
{
if (response != ''){
// Response mode
message = document.getElementById('nameCheckFailed');
submit = document.register.submitform;
if (response == 1){
message.className = 'registererror';
submit.disabled = true;
}else{
message.className = 'registererrorhidden';
submit.disabled = false;
}
}else{
// Input mode
url = 'register.php?do=checkusername&username=' + input;
loadXMLDoc(url);
}
}
with:
function checkName(input, response)
{
if (response != ''){
// Response mode
var message = document.getElementById('nameCheckFailed');
var submit = document.register.submitform;
if (response == 1){
message.className = 'registererror';
submit.disabled = true;
}else{
message.className = 'registererrorhidden';
submit.disabled = false;
}
}else{
// Input mode
url = 'register.php?do=checkusername&username=' + input;
loadXMLDoc(url);
}
}
This error seems pretty strange to me since the same code is working fine for me :)
Zero Tolerance
05-18-2005, 09:32 AM
MrNase - I'm assuming the 'register' in the JS is the name of the form? I would advise using:
document.forms['register'] To call the object, it seems more browser compliant. :)
- Zero Tolerance
CompuJonathan
05-18-2005, 09:27 PM
MrNase,
Brilliant! The first fix fixed it! :)
Great job! :banana:
MrNase
05-19-2005, 11:35 AM
Just like Zero Tolerance said: Somehow he didn't select the submit button.. And this was necessary to disable it :)
Iam glad it's working. What browser are you using btw. ?
CompuJonathan
05-19-2005, 11:51 PM
Internet Explorer 6.0
Thanks again!
- Jonathan
T3MEDIA
05-24-2005, 05:49 PM
Just like Zero Tolerance said: Somehow he didn't select the submit button.. And this was necessary to disable it :)
Iam glad it's working. What browser are you using btw. ?Has this been updated to relect these fixes?
I will ask but if you dont want to please tell me here.
Can you do this as well for the referrer?
Users put peoples names in and if its spelled wrong they get an error and dont read properly and assume its their name that is invalid.
If not thanks.
sv1cec
06-08-2005, 12:02 PM
One question for the ignorants. Why are the phrases added in language 0 and not in -1?
Thank you.
Snake
06-22-2005, 10:26 AM
Will this be available for 3.5?
sketch42
07-15-2005, 12:35 AM
is it possible to have the output generate a similiar username that is available or would that add to many queries?
sketch42
07-19-2005, 11:26 AM
is it possible to have the output generate a similiar username that is available or would that add to many queries?
so is it possible??
* sketch42 clickity clicks install
MrNase
07-20-2005, 09:45 AM
I had this working for one hour or two.. But that produced some funny usernames :D
It is possible but I don't release it as an addon to this vB 3 version. I'll port the hack over to vB 3.5 and I *may* include a username generator once I figured out how to make usable usernames ;)
paul41598
07-20-2005, 12:21 PM
Not sure I understand this hack. Does VB 3.0.7 not already check upon registration if a username already exists?
Please advise, otherwise, nice hack ;)
MrNase
07-20-2005, 06:04 PM
It does, but my the default system the user get's the error message after clicking 'submit'.
With this hack he gets an error message instantly after entering the username. I basically eleminates the need of going back one page to enter a new username when the current one is already registered :)
slank
09-14-2005, 09:08 PM
gotta love ajax...clicking install now ;)
Xtrato
11-15-2005, 07:18 PM
can i use vb3.5 with this???
Snake
12-26-2005, 12:06 PM
Works on 3.5.2?
Snake
01-04-2006, 04:31 PM
Hello?
Jolten
03-06-2006, 10:00 PM
Well I can't get it to function with 3.0.6. No errors or anything, just no functionality for AJAX.
Chirag patel
06-25-2006, 07:47 PM
Does this work on 3.5.X?
Or can someone point me to some direction to get this working on 3.5.X please.........?!?!?!?!?
I followed all the instructions but it is still not working. I am sure that I did everything right. I am using 3.5.4
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.