suma237 Posted February 27, 2007 Share Posted February 27, 2007 Hai, im unable to go to next page after database validation....pls find the error in this page Main form-- <!-- theform.php --> <div style="padding: 10px;"> <div id="messagebox"></div> <form method="get" name="myForm" action="" > <input type="hidden" name="submit" value="send"> Your Name<br /> <input id="yourname" type="text" value="" /> <br /> Your MailId<br /> <input id="mailid" type="text" value="" /> <input type="button" value="Submit" onclick="validateform()" /> <div align="right"><a href="javascript:close()">close</a></div> </form> </div> <script language="javascript"> function validateform (){ var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } thevalue=document.getElementById('yourname').value; themail=document.getElementById('mailid').value; serverPage = "validator.php?sstring=" + thevalue+ "&themail=" + themail ; //alert(serverPage); objID = "messagebox"; var obj = document.getElementById(objID); ajaxRequest.open("GET", serverPage,true); //ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajaxRequest.onreadystatechange = function() { if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) { obj.innerHTML = ajaxRequest.responseText; }} ajaxRequest.send(null); } </script> 2.validator.php <?php include("includes/db.inc.php"); $db=new DB; $db->open(); //validator.php //A list of valid names. //Again, this would usually come from a database. //echo'<pre>';print_r($_REQUEST);echo'</pre>'; if($_GET['sstring']==""){ //Then return with an error. ?> <span style="color: #FF0000;">Name should not be blank...</span><?php } else if($_GET['themail']=="") {?> <span style="color: #FF0000;">mailid should not be blank...</span> <?php } else if(!ereg ("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_GET['themail'])) {?> <span style="color: #FF0000;">Email format is incorrect ...</span> <? }else if($_GET['sstring']!="" && $_GET['themail']!=""){ ?><span style="color: #FF0000;">Form would now submit...</span><?php //echo'<pre>';print_r($_GET);echo'</pre>'; $nam=$_GET['sstring']; $ma=$_GET['themail']; $sql="select * from tbl_login where name='$nam' and mail='$ma'"; $result=$db->query($sql)or die($db->error()); $numrows=$db->numRows($result); if($numrows>0) { //header('Location:form2.php'); ?> <!--<script language="javascript"> alert("sss"); window.location.href="form2.php"; </script> <span style="color: #FF0000;">Thanks </span> --> <? } else{?> <span style="color: #FF0000;">Invalid Login</span> <?} } ?> Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted March 1, 2007 Share Posted March 1, 2007 suma237, After getting rid of the syntax errors in your posted code, I got it to work, but this doesn't really seem to be something that needs AJAX. Anyway, here is the code I got to work. (Your original code was complaining about headers already sent, because of : <span style="color: #FF0000;">Form would now submit...</span>) Scot L. Diddle, Richmond VA theForm.html <html> <head> <script language="javascript"> function validateform (){ var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } thevalue=document.getElementById('yourname').value; themail=document.getElementById('mailid').value; serverPage = "validator.php?sstring=" + thevalue+ "&themail=" + themail ; //alert(serverPage); objID = "messagebox"; var obj = document.getElementById(objID); ajaxRequest.open("GET", serverPage,true); //ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajaxRequest.onreadystatechange = function() { if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) { obj.innerHTML = ajaxRequest.responseText; }} ajaxRequest.send(null); } </script> </head> <body> <!-- theform.php --> <div style="padding: 10px;"> <div id="messagebox"></div> <form method="get" name="myForm" action="" > <input type="hidden" name="submit" value="send"> Your Name <input id="yourname" type="text" value="" /> Your MailId <input id="mailid" type="text" value="" /> <input type="button" value="Submit" onclick="validateform()" /> <div align="right"><a href="javascript:close()">close</div></a> </form> </div> </body> </html> validator.php <?php //include("include/db.inc.php"); //$db=new DB; //$db->open(); //validator.php //A list of valid names. //Again, this would usually come from a database. //echo // print_r($_REQUEST); if($_GET['sstring']==""){ //Then return with an error. ?> <span style="color: #FF0000;">Name should not be blank...</span> <?php } else if($_GET['themail']=="") {?> <span style="color: #FF0000;">mailid should not be blank...</span> <?php } else if(!ereg ("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_GET['themail'])) { ?> <span style="color: #FF0000;">Email format is incorrect ...</span> <?php }else if($_GET['sstring']!="" && $_GET['themail']!=""){ header('Location:processSubmit.php'); exit; $nam=$_GET['sstring']; $ma=$_GET['themail']; $sql="select * from tbl_login where name='$nam' and mail='$ma'"; $result=$db->query($sql)or die($db->error()); $numrows=$db->numRows($result); if($numrows>0) { header('Location:form2.php'); ?> <!--<script language="javascript"> alert("sss"); window.location.href="form2.php"; </script> <span style="color: #FF0000;">Thanks </span> --> <?php } else{?> <span style="color: #FF0000;">Invalid Login</span> <?php } } ?> processSubmit.php <?php echo "Were Here ... Submit Worked ! <br /> \n"; ?> Quote Link to comment Share on other sites More sharing options...
suma237 Posted March 2, 2007 Author Share Posted March 2, 2007 Hai, Thanks for ur reply.my requirment is after valid the feild name and mailid,i want to go to next page. After submitimg,if the feild value will match with the databse value then i want to go to next page. Example-Same function of gmail main page..if u have any code like that pls send me.please..... Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted March 2, 2007 Share Posted March 2, 2007 suma237, Hello, That's what I thought you wanted to do, which is why I posted that I did not think that AJAX was the solution you were looking for. The power of AJAX is that it allows for writing portions of the current page without re-writing the whole page. It sounds like you just need a simple action="somePHP.php" linked to a form submit button... The validation could take place after the submit is entered. Scot L. Diddle, Richmond Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.