Forums

Ajax style username checker ?

Grimbly 19 Oct, 2008
I was just wondering if any knows of an easy way to implement an ajax style username checker to validate a username before submission.
I was thinking that perhaps JFactory could come in handy for this but I'm not 100% certain about that, anyway if anybody has an idea or suggestion I would love to hear it.

James
GreyHead 19 Oct, 2008
Hi Grimbly,

I Googled and found a Joomla 1.0 version by pixnet at joomlahacks.com (registration required to download)

Bob
Grimbly 20 Oct, 2008
Yep I noticed that one too and downloaded it but haven't really given it a hard look yet. I'm using J! 1.5.6 so I imagine there will be a bit of modification required and I'm not real familiar with Joomla's internal working so I wouldn't know where to begin. I should also mention that I'm currently using CF 3.0 Stable in case that makes any difference.

I've attached the 1.0 version .zip from joomlahacks.com in case you or anyone else was interested in taking a look at it.

Thanks for checking though GreyHead, and thanks for CF and all the help so far on this forum. You guys have a really good thing going here, just wanted to let you know I appreciate it.
GreyHead 20 Oct, 2008
Hi Grimbly,

You are correct - the user registration function is quite different in Joomla 1.5. I think it shoudl be possible to hack the ChronoForms Registration plugin though . . .

There are two core chunks of code in pixnet's mod: a JavaScript function
function ajaxFunction()  {
  var xmlHttp;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) {
    // Internet Explorer
    try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
      try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }

  var url = "<?php echo $mosConfig_live_site;?>";
      url = url+"/usernamehint.php?username=";
      url = url+document.getElementById("uname").value;

  xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState==4) {
        var r=xmlHttp.responseText;
        if (r != "") {
          document.getElementById("unameHint").innerHTML=r;
        }
      }
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
  function clearcheck()  {
    document.getElementById("unameHint").innerHTML="";
  }
and a php page that returns an image link
<?php
$r="";
if ($_GET["username"]) {
    require_once( 'configuration.php' );
    $db_conn = mysql_connect($mosConfig_host, $mosConfig_user, $mosConfig_password);
    if ($db_conn) {
        $db_open=mysql_select_db($mosConfig_db,$db_conn);
        if ($db_open) {
            $sql = "
                SELECT username 
                    FROM ".$mosConfig_dbprefix."users 
                    WHERE username='".$_GET["username"]."'";
            $result=mysql_query($sql, $db_conn);
            if (mysql_affected_rows() > 0) {
                $r = "<img src=\"".$mosConfig_live_site."/images/stop.png\" />";
            } else {
                $r = "<img src=\"".$mosConfig_live_site."/images/ok.png\" />";
            }
            mysql_free_result($result);
        } else {
            $r="Bad database";
        }
        mysql_close($db_conn);
    } else {
        $r="Bad databse";
    }
}
echo $r;
return;
?>

Bob
Max_admin 20 Oct, 2008
Hi Grimbly,

you can also write a simple SQL query at the Server side validation box to check the same username and return some error if the same username was found, this will not be AJAX though.

Cheers,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Grimbly 20 Oct, 2008
Hey Max, thanks for the input I'll be using SQL queries for alot of the other server-side validation but I really was hoping to check the usernames in realtime, so they wouldn't have to submit first. It really doesn't have to be Ajax specifically just Ajax like. If you go to this link Live Validation Examples you can see the current client-side validation I'm using. I was hoping I could style a name checker with similar functionality and style. They have a custom function which I really need to figure out how to use that may help but for now I'm not sure how to implement that.

GreyHead, I'm really doubting I would know where to begin if I decided to hack the CF registration plugin. ๐Ÿ˜€
But I open to suggestion all the same.

Lastly, while I have you guys here would either of you be able to point me to the code that controls the captcha error message and its style, I was hoping to re style that to stay in keeping with the rest of the form.


BTW, I just realized I haven't given you guys a review yet so I go do that right now.

Thanks again for all the help guys,
James
GreyHead 21 Oct, 2008
Hi Grimbly,

I took a quick look at hacking the Joomla Registration plugin this morning. I think it's possible, but not trivial - the AJAX needs to call back to a PHP function and I'm nto quite clear how to make that available from an included file. I just got 'You are not allowed to access this form' messages and couldn't quickly see what was generating them :-(

Just had an even briefer look at Live Validation and that looks very similar to the Dexagogo validation that ChronoForms uses.

Bob
Max_admin 21 Oct, 2008
Hi Grimbly,

you can create a PHP file with the PHP code to make the username checking and call it with the AJAX code, get the AJAX response and do what you like.

see this mootools ajax example :
$('start').addEvent('click', function(e) {
	e = new Event(e).stop();
 
	var url = "http://demos111.mootools.net/demos/Ajax/lipsum.html";
 
	/**
	 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
	 * to do add your own Ajax depended code.
	 */
	new Ajax(url, {
		method: 'get',
		update: $('log')
	}).request();
});


Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Grimbly 25 Oct, 2008
Hey guys sorry for taking so long to respond. I haven't had time to review the info. you've given me so far, hopefully I will this weekend though. I got sidetracked with the server-side verification and ran into an issue. I think you guys might be able to help.

In the CB plugin configuration there is a field named "lastupdatedate" I was not planning on using that and wanted to change it to "acceptedterms" and link that to the corresponding column in jos_comprofiler but cannot find the code I need to change
This will be used to verify that new users have agreed to my Terms of Service policy.
If either of you could point me in the right direction I would really appreciate it.

Thanks a bunch,

James
Max_admin 26 Oct, 2008
Hi James, you mean you want to add a new field or change an existing one ? do what you need then open the plugin configuration page, reconfigure and save so it has the latest data!

Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Grimbly 26 Oct, 2008
I would prefer to modify. I think it might be easier than adding.

I just need to verify that users accepted my Terms of Service. There is a field in the jos_comprofiler table called "acceptedterms" and I just wanted to send my data to that field.
For testing I've got it linked to the "firstname" field, as the first name is not needed at my site, but it would be nice to have it in a more appropriate field๐Ÿ™‚

So to sum it all up, I would like to change which column the CB plugin sends the firstname data to, specifically i'd like to change the column from "firstname" to "acceptedterms" in the jos_comprofiler table.
The field name in the plugin config could stay the same for all i care, I just wanted to re-route where the data was sent.

Thanks again,

James
Max_admin 26 Oct, 2008
the CB plugin has 5 default fields, name,username,email,pass, verify pass, other fields are CB fields, change them as you like then reconfigure the plugin and save!

Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
gg4j 31 Oct, 2008
Hi guys, I add this reply linked to Multiple Upload thread.

The idea is to check a validation in a form on the fly:
1) The users input his user/password
2) VALIDATION? through ajax as suggested here: http://www.chronoengine.com/forums.html?cont=posts&f=2&t=11379#p15698
3) if the validation is ok (return value true) then uses input other fields
4) if the validation is not ok (false), a registration phase is required. Or alternatively, other fields appear dynamically for inserting the registration (in this way, both personal data of users and input field can be stored in the same db_table)

I'm not fond in Ajax and Js... some tips? Ready files easy to adapt?๐Ÿ˜ถ
Max_admin 31 Oct, 2008
Hi gg4j,

I can't understand what you are trying to do, the AJAX code needs to be edited depending on your form code and fields names and PHP file for AJAX to be able to do the username check!

Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.