I got a problem ... Please help as fast as you can

Discussion in 'JavaScript' started by fasafeso, Apr 5, 2011.

  1. #1
    I was working on website and need to do sign up stuf ... but i got a problem here and search alot without finding the answerd ... !!

    the problem is when i validation the text field ... I got an html page with some form onclick there's a javascript function running out to validate the text field and after validation it's send an error number to php page ... and the php page read the error and show it if exist ... but the problem is when I redirect from javascript function to php page the php page cannot see the form value from the html ... and don't know how to do it ... !!!

    her is the html code :

    
    <div align="center" > <!-- <script language=javascript >sign_up();</script> style="padding: 100px 0 0 250px;"><!-- enctype="multipart/form-data" onSubmit="return sign_up();"-->
    
    
    <div id="login-box" align="left">
    <form action="signup.php?id=signup&sen=<script language=javascript >sign_up();</script>" method="post" name="form1"   >
    <H2>Sign Up</H2>
    <div id="login-box-name" style="margin-top:20px;">User Name :</div><div id="login-box-field" style="margin-top:20px;"><input name="username" id="username" class="form-login" title="Username" value="" size="30" maxlength="2048" /></div>
    <div id="login-box-name">Password :</div><div id="login-box-field"><input name="password" type="password" class="form-login" title="Password" value="" id="password" size="30" maxlength="2048" /></div>
    <br />
    <div id="login-box-confirm" style="vertical-align:middle;">Confirm&nbsp;&nbsp;&nbsp;&nbsp; password :</div><div id="login-box-field"><input name="confirm" id="confirm" type="password" class="form-login" title="Password" value="" size="30" maxlength="2048" /></div>
    <br />
    <div id="login-box-name">Email :</div><div id="login-box-field"><input name="email" id="email" type="text" class="form-login" title="Password" value="" size="30" maxlength="2048" /></div>
    <div  id="ajax"></div>
     
    <span class="login-box-options">
    <!--
    <table cellpadding="0" cellspacing="0">
    <tr>
    <td width="120">&nbsp;
    
    </td>
    <td align="left">
    <a href="signup.php">Sign up</a>
    </td>
    <td align="right">
     <a href="forget.php" style="margin-left:30px;">Forgot password?</a></span>
     </td>
     </tr>
     </table>
    <br />
    <br />
    -->
    </td>
    <div style="margin-left:120px;">
    <INPUT TYPE="image" SRC="images/signup-btn.png" HEIGHT="40" WIDTH="103" BORDER="0" ALT="Submit Form" >
    </div>
    <!--<a href="signup.php?id=signup"><img src="images/login-btn.png" width="103" height="42" style="margin-left:90px;" /></a>onclick="sign_up();"-->
    </form>
    </div>
    
    </div>
    
    Code (markup):
    notic : don't care about css tags ... i didn't upload the css file with this post .. !!


    and this is a java script code :

    
    
    // ------- sign up check --------
    
    
    function sign_up()
    {       
    		var sen="0";
    		
    		
    		var name=document.getElementById('username').value;
            var email=document.getElementById('email').value;
            var password=document.getElementById('password').value;
            var con=document.getElementById('confirm').value;
    		
    		
    		
     		if (name=='' || email == '' || con =='' ||password =='')
    		 sen=1;
    		 
    		if(password != con )
    		sen =2;
    		
    		
    		 
    		var at='@';
    		var dot='.';
    		var lat=email.indexOf(at);
    		var lstr=email.length;
    		var ldot=email.indexOf(dot);
    		
    		
    		if (email.indexOf(at)==-1)
    		sen=3;
    		
    		if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr)
    		sen=3;
    
    		if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr)
    		sen=3;
    
    		if (email.indexOf(at,(lat+1))!=-1)
    		sen=3;
    
    		if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot)
    		sen=3;
    
    		if (email.indexOf(dot,(lat+2))==-1)
    		sen=3;
    		
    	 	if (email.indexOf(' ')!=-1)
    		sen=3;
    		
    		
    		
        	var illegalChars =  /[\(\)\<\>\,\;\:\\\"\[\]]/; // allow letters, numbers, and underscores
     
        	if ((username.length < 4) || (username.length > 15)) 
    		sen=4;
    		
    		else if (illegalChars.test(username.value)) 
    		sen=4;
    		
        
    	
    		if ((fld.value.length < 5) || (fld.value.length > 32))
    		sen=5;
    		
    		else if (illegalChars.test(fld.value)) 
    		sen=5;
    		
    		
    		var id = "signup";
    		var string = "signup.php?id="+id+"&sen="+sen;
    		//document.write(string);
     		//window.location.href=string;
    		return sen;
    }
        
    
    
    Code (markup):


    and last the php code :


    
    if ( $id == 'signup' )
    {	echo $sen;
    	echo $_POST['username'];
    	$msg="";
    	}
    
    PHP:


    and thanks any why ... !!!
     
    fasafeso, Apr 5, 2011 IP
  2. Tim_Myth

    Tim_Myth Peon

    Messages:
    741
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Javascript validation is useless...any bot can bypass it. Do your validation in your php script instead. This will solve your problem since the values will get passed to the script and it will output the correct error message. It will also solve the problem of bots that ignore javascript.

    If you want a spiffy web2.0 ajax thingy, then fire the validation javascript on the onblur event. Plenty of tutorials for that online.
     
    Tim_Myth, Apr 5, 2011 IP
  3. fasafeso

    fasafeso Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mmm ... ok ok got it ... !!!

    I was doin it in php ... but don't find a pattern for username or email ... so i doin it in javascript ... but still have a problem !!! :D

    if you got a code for my problem i would be grateful .... because i'm tired of searching in the internet ... !!!

    and thx tim_myth any way .. !!!
     
    fasafeso, Apr 5, 2011 IP
  4. Tim_Myth

    Tim_Myth Peon

    Messages:
    741
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Tim_Myth, Apr 5, 2011 IP
  5. fasafeso

    fasafeso Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thx man your the best .. i don't know what to say but thanks ... !!
    I wanna ask you if you got something for name validation in php .. but thanks for this code !!!
     
    fasafeso, Apr 5, 2011 IP
  6. Tim_Myth

    Tim_Myth Peon

    Messages:
    741
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Name validation... not really because names can be all over the board. eg Izaak, Tim, Shanequa, Ibn Fazullahd III, etc. The only thing I ever do with names is santize the input (eg mysql_real_escape_string($_POST['fname']) when storing it in an SQL database or htmlspecialchars($_POST['lname']) when I'm displaying user input.).
     
    Tim_Myth, Apr 6, 2011 IP
  7. fasafeso

    fasafeso Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    mmm aha got it ... so I will do validation for just an email .. !!! ok I'll do it in php ... Thx alot tim_myth your the best ... !!!

    thxxxxxxxxxxxxxxxxxxxxx
     
    fasafeso, Apr 6, 2011 IP