Check availability issue

This forum is for general questions about extensions for Joomla! version 1.5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
User avatar
sashikanta
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri Jun 05, 2009 10:35 pm

Check availability issue

Post by sashikanta » Thu Jan 12, 2012 7:20 pm

I am just adding a new feature to my Joomla TPJOBS component although it's not a good/complete/active component but just I'm adding a user name Availability checker but its not working because it may be due to in this component.

Check the website : http://jobodisha.com/component/tpjobs/r ... ernew.html
[Click on Check availability which is not working]

My Joomla Component Directory is : \public_html\components\com_tpjobs\

Editing tpjobs.html.php(exiting) and username_validate.php (created)

My Javascript AJAX Code : which is under tpjobs.html.php

Code: Select all

<script type="text/javascript">
		<!--
  //function to create ajax object
  function pullAjax(){
    var a;
    try{
      a=new XMLHttpRequest()
    }
    catch(b)
    {
      try
      {
        a=new ActiveXObject("Msxml2.XMLHTTP")
      }catch(b)
      {
        try
        {
          a=new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch(b)
        {
          alert("Your browser broke!");return false
        }
      }
    }
    return a;
  }
 
  function username_validate()
  {
    site_root = '';
    var x = document.getElementById('username');
    var msg = document.getElementById('msg');
    user = x.value;
 
    code = '';
    message = '';
    obj=pullAjax();
    obj.onreadystatechange=function()
    {
      if(obj.readyState==4)
      {
        eval("result = "+obj.responseText);
        code = result['code'];
        message = result['result'];
 
        if(code <=0)
        {
          x.style.border = "1px solid #FF0084";
          msg.style.color = "#FF1A00";
        }
        else
        {
          x.style.border = "1px solid #008C00";
          msg.style.color = "#73880A";
        }
        msg.innerHTML = message;
      }
    }
    obj.open("GET",site_root+"username_validate.php?username="+user,true);
    obj.send(null);
  }
  //-->
</script>
<style>
#username {
	border: 1px solid #000;
}
</style>
My username_validate.php file

Code: Select all

<?php
	defined('_JEXEC') or die('Restricted access');
	 

	$user = strip_tags(trim($_REQUEST['username']));
	 
	if(strlen($user) <= 0)
	{
	  echo json_encode(array('code'  =>  -1,
	  'result'  =>  'Invalid username, please try again.'
	  ));
	  die;
	}
	
	$db =& JFactory::getDBO(); //get database object
	$db->setQuery("Select username FROM #__users where username = '$user'")
	 
	$db->query(); //do actual query
	
	$result = $db->getAffectedRows(); //return affected rows
	 
	if($result)
	{
	  echo json_encode(array('code'  =>  1,
	  'result'  =>  "Success,username $user is still available"
	  ));
	  die;
	}
	else
	{
	  echo  json_encode(array('code'  =>  0,
	  'result'  =>  "Sorry but username $user is already taken."
	  ));
	  die;
	}
	die;
?>
You do not have the required permissions to view the files attached to this post.

 
 
Locked

Return to “Extensions for Joomla! 1.5”