0

Morning, and greeting to all~
I'm building a registeration form for a forum

i got 3 input : User Name, password, and email

In this case i use ajax to do the duplicate validation check
once the registering user entered a name or email that has been took by other ppl
it will run the validation and show some message like "valid username" "duplicate username"

but i got a problem which is i dono how to disable the "Register" button while the validation showing "Duplicate username" and user ignore the message.

here my code (if you need it): php [form]

<?php 
include 'dbconn.php'; 
include 'Header.php';
if(isset($_COOKIE['Author']))
{
	echo "<div id='Display'>";
	echo "You already have an account!</div>";
}
else
{
echo "<form name='frmRegisteration' action='Register.php' method='post' onSubmit='return DataValidator()'>";
	$name = $_POST['txtname'];
	$password = $_POST['txtpasswd'];
	$email = $_POST['txtemail'];
	if(isset($name,$password,$email))
	{
		$qry_insertauthor = "INSERT INTO author (user_name,passwd,email) VALUES ('".$name."','".$password."','".$email."')";
		$arr_insertauthor = mysql_query($qry_insertauthor);
	}else{ 
		echo "<div id='Display'>";
		echo "<em>&nbsp;&nbsp;&nbsp;</em>Please fullfill all the information required below : </div>";
	}
echo "<div id='Register' style='margin-top:10px;'><table width='100%'>
	<tr><td width='15%'><em>Name     :</em><br /></td><td><input name='txtname' id='regName' size='25' onKeyUp='UserValidate(this.value)' onBlur='Disablebutton(document.getElementById('txterror').value)'/>
	<label id='txterror'>* Please Enter your name here</label></td></tr>
	<tr><td><em>Password :</em><br /></td><td><input type='password' name='txtpasswd' id='regPasswd' size='25' maxlength='15' /></td></tr>
	<tr><td><em>E-mail    :</em><br /></td><td><input name='txtemail' id='regEmail' size='25' onKeyUp='emailValidate(this.value)' />
	<label id='txterror2' on>* Please Enter your email here</label></td></tr></table>
	<em>&nbsp;</em><input type='submit' name='btnRegister' id='regbtnRegister' value='Register'/></form>
	</div><input type='hidden' id='Receiver'>";
}
include'Footer.php'; 
?>

Java

function UserValidate(name)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   		result=xmlhttp.responseText; 
		document.getElementById("Receiver").innerHTML= result; 
    }
  }
xmlhttp.open("GET","RegisterAJAX.php?Name="+name,true);
xmlhttp.send();
}
function emailValidate(email)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("Receiver").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","RegisterAJAX.php?Email="+email,true);
xmlhttp.send();

Ajax

<?php include("dbConn.php") ?>
<?php
if(isset($_GET["Name"])){
	$name=$_GET["Name"];
	$qry_getname = "SELECT COUNT(user_name) FROM author WHERE user_name='".$name."'";
	$arr_getname = mysql_query($qry_getname);
	$result = mysql_fetch_assoc($arr_getname);
		if($result['COUNT(user_name)'] >=1)
		{echo " *The name were duplicated! Please Re-Enter another name.";
		echo " *Disabled";
		}else{ echo " *Valid User Name.";}
}
else if(isset($_GET["Email"])){
	$email=$_GET["Email"];
  	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
    $qry_getemail = "SELECT COUNT(email) FROM author WHERE email='".$email."'";
	$arr_getemail = mysql_query($qry_getemail);
	$result = mysql_fetch_assoc($arr_getemail);
		if($result['COUNT(email)'] >=1)
		{echo " *The email were duplicated! Please Re-Enter another E-mail Address.";
		echo " *Disabled";
		}else{ echo " *Valid Email.";}
	}
	else{ echo " *Your Email Format Are Invalid !";
			echo " *Disabled";} 
}
?>

Please Help i already stuck in this probelm for 4 days!
i'm a newbie and my senior don't give a hand Thank you sososo much foe help in advanced!

Edited by Nybuler: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by hielo
0

try:

<?php 
include 'dbconn.php'; 
include 'Header.php';
if(isset($_COOKIE['Author']))
{
	echo "<div id='Display'>";
	echo "You already have an account!</div>";
}
else
{
echo "<form name='frmRegisteration' action='Register.php' method='post' onSubmit='return DataValidator()'>";
	$name      = mysql_real_escape_string($_POST['txtname']);
	$password  = mysql_real_escape_string($_POST['txtpasswd']);
	$email     = mysql_real_escape_string($_POST['txtemail']);
	if(isset($name,$password,$email))
	{
		$qry_insertauthor = "INSERT INTO author (user_name,passwd,email) VALUES ('".$name."','".$password."','".$email."')";
		$arr_insertauthor = mysql_query($qry_insertauthor);
	}else{ 
		echo "<div id='Display'>";
		echo "<em>&nbsp;&nbsp;&nbsp;</em>Please fullfill all the information required below : </div>";
	}
echo "<div id='Register' style='margin-top:10px;'><table width='100%'>
	<tr><td width='15%'><em>* Name     :</em><br /></td><td><input name='txtname' id='regName' size='25' onchange='UserValidate(this.value)' />
	<label id='txterror' style="visibibility:hidden;">Please Enter your name here</label></td></tr>
	<tr><td><em>Password :</em><br /></td><td><input type='password' name='txtpasswd' id='regPasswd' size='25' maxlength='15' /></td></tr>
	<tr><td><em>* E-mail    :</em><br /></td><td><input name='txtemail' id='regEmail' size='25' onchange='emailValidate(this.value)' />
	<label id='txterror2'  style="visibibility:hidden;">Please Enter your email here</label></td></tr></table>
	<em>&nbsp;</em><input type='submit' name='btnRegister' id='regbtnRegister' value='Register' disabled="disabled" /></form>
	</div><input type='hidden' id='Receiver'>";
}
include'Footer.php'; 
?>

<script type="text/javascript">
//1 for 'username' and 1 for 'email'
var possibleDuplicates=2;

function UserValidate(name)
{
     if (window.XMLHttpRequest)
       {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
       }
     else
       {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     xmlhttp.onreadystatechange=function()
       {
       	if (xmlhttp.readyState==4 && xmlhttp.status==200)
         {
        	result=xmlhttp.responseText; 
			if( result.indexOf('*Valid')>-1 )
			{
				--possibleDuplicates;
				document.getElementById('txterror').style.visibility='hidden';
			}
			else
			{
				++possibleDuplicates;
				document.getElementById('txterror').style.visibility='visible';
			}

			if(0==possibleDuplicates)
			{
				document.getElementById('regbtnRegister').disabled=false;
			}
			else
			{
				possibleDuplicates=possibleDuplicates>2?2:possibleDuplicates;
				document.getElementById('regbtnRegister').disabled=true;
			}

     		document.getElementById("Receiver").innerHTML= result; 
         }
       }
     xmlhttp.open("GET","RegisterAJAX.php?Name="+name,true);
     xmlhttp.send();
}
function emailValidate(email)
{
     if (window.XMLHttpRequest)
       {	// code for IE7+, Firefox, Chrome, Opera, Safari
       		xmlhttp=new XMLHttpRequest();
       }
     else
       {	// code for IE6, IE5
       		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     
	 xmlhttp.onreadystatechange=function()
       {
       if (xmlhttp.readyState==4 && xmlhttp.status==200)
         {
     		if( xmlhttp.responseText.indexOf('*Valid')>-1 )
     		{
				--possibleDuplicates;
				document.getElementById('txterror2').style.visibility='hidden';
     		}
			else
			{
				++possibleDuplicates;
				document.getElementById('txterror2').style.visibility='visible';
			}

			if(0==possibleDuplicates)
			{
				document.getElementById('regbtnRegister').disabled=false;
			}
			else
			{
				possibleDuplicates=possibleDuplicates>2?2:possibleDuplicates;
				document.getElementById('regbtnRegister').disabled=true;
			}
   			document.getElementById("Receiver").innerHTML=xmlhttp.responseText;
         }
       }
     xmlhttp.open("GET","RegisterAJAX.php?Email="+email,true);
     xmlhttp.send();
}
</script>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.