Eternal Loop on "onAfterValidate"

I am getting a very bizarre response when I run “onAfterValidate” on my form. Sometimes the form will update properly, however most of the time I get a stack overflow error and if I put a javascript alert function to see what the program is actually doing, it loops the alert over and over. I have to shut the window to stop it.

<?
session_start(); 

require_once('xclass.php');
require_once("conf.php");

	$log = new login;
	
	if(!($log->verify_access() == true)) {
		header("Location: http://$domain/admin/");
	}



?>

<!DOCTYPE HTML>
<html>
	<head>
        <meta  name = "viewport" content = "initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no">
		<!-- <link rel="stylesheet" href="<?=$codebase?>/touchui.css" type="text/css">
		<script src="<?=$codebase?>/touchui.js" type="text/javascript"></script>
		-->
		
		<script type="text/javascript" charset="utf-8">
		/*
		var isMobile = {
		    Android: function() {
		        return navigator.userAgent.match(/Android/i) ? true : false;
		    },
		    BlackBerry: function() {
		        return navigator.userAgent.match(/BlackBerry/i) ? true : false;
		    },
		    iOS: function() {
		        return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
		    },
		    Windows: function() {
		        return navigator.userAgent.match(/IEMobile/i) ? true : false;
		    },
		    any: function() {
		        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
		    }
		};
		
		/*  Check for a specific mobile platform
		if( isMobile.iOS() ) 
			alert('iOS'); */
		/*
		if ( isMobile.any()) {
			alert('Using a Mobile Device');
		}
		else {
			alert('Using a Non Mobile Device');
		}
		*/		
		</script>
		
		<link rel="STYLESHEET" type="text/css" href="<?=$codebase?>/dhtmlx.css">
    	<link rel="STYLESHEET" type="text/css" href="<?=$codebase?>/dhtmlxgrid.css">
    	<link rel="STYLESHEET" type="text/css" href="<?=$codebase?>/skins/dhtmlxgrid_dhx_skyblue.css">
    	<link rel="STYLESHEET" type="text/css" href="<?=$codebase?>/skins/dhtmlxwindows.css">
    	<link rel="STYLESHEET" type="text/css" href="<?=$codebase?>/skins/dhtmlxwindows_dhx_skyblue.css">
		
		<script src="<?=$codebase?>/dhtmlx.js" type="text/javascript"></script>
	    <script src="<?=$codebase?>/connector.js" type="text/javascript"></script>
	    <script src="<?=$codebase?>/dhtmlxcommon.js"></script>
	    <script src="<?=$codebase?>/dhtmlxgrid.js"></script>
	    <script src="<?=$codebase?>/dhtmlxgrid_filter.js"></script>
	   
	    <script src="<?=$codebase?>/dhtmlxgridcell.js"></script>
	    <script src="<?=$codebase?>/dhtmlxdataview.js"></script>
	    <!--<script src="<?=$codebase?>/dataprocessor.php"></script>
	     <script src="<?=$codebase?>/dhtmlxdataprocessor_debug.js"></script>-->
	    <script src="<?=$codebase?>/dhtmlxcommon.js"></script>
	    <script src="<?=$codebase?>/dhtmlxcontainer.js"></script>
	    <script src="<?=$codebase?>/dhtmlxwindows.js"></script>
	     <script src="<?=$codebase?>/dhtmlxform.js"></script>

	    
	    
	    
	   
	    
	    <style>
	        /*these styles allow dhtmlxLayout to work in fullscreen mode in different browsers correctly*/
	        html, body {
	           width: 100%;
	           height: 100%;
	           margin: 0px;
	           overflow: hidden;
	           background-color:white;
	        }
   		</style>
   		
   		
   		
   		
   		<script type="text/javascript">
   			
   			var MasterID = "<?=$_SESSION[user_id]?>";
   			
   			function checkPass(id, pass) {
		
				var ajaxRequest;  // The variable that makes Ajax possible!
				
				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;
						}
					}
				}
			
			
				// Create a function that will receive data sent from the server
				ajaxRequest.onreadystatechange = function(){
					
					if(ajaxRequest.readyState == 4) {
						
						var RESP = ajaxRequest.responseText;
						
						if (RESP == "FAIL") {
								var passFail = new dhtmlXWindows();
								var win = passFail.createWindow("passFail", 100, 200, 425, 200);
								passFail.window("passFail").center();
								passFail.window("passFail").setText("Password Fail!");
								passFail.window("passFail").attachURL("passFail.html");
						}
						if (RESP == "PASS") {
								alert ("Contact Form Validate - With Pass Update");
								contactForm.validate();
								//contactForm.send("./updateCoDetails.php", "post");
								//contactForm.clear();
								//contactForm.load("./getCoInfo.php?id=" + MasterID);
						}
							
						
						
					}
				}
				
				
	
				var queryString = "?ID=" + id + "&password=" + pass;
				ajaxRequest.open("GET", "checkPass.php" + queryString, true);
				ajaxRequest.send(null); 
		
			}
   			
   			/* End Ajax Request */
   			
   			
   			
   			var layout,menu,toolbar,contactsGrid,contactForm;
			dhtmlx.image_path = "<?=$codebase?>/imgs/";
			dhtmlxEvent(window,"load",function(){
			    //application code goes here
			    
			    //layout
			    layout = new dhtmlXLayoutObject(document.body,"2U");
			    layout.cells("a").setText("Contact Information");
			    layout.cells("b").setText("Database Manager");
			    layout.cells("b").setWidth(500);
			    
				/* Add Toolbar to "Database Manager" */
				toolbar = layout.cells("b").attachToolbar();
				toolbar.setIconsPath("<?=$codebase?>/icons/");
				toolbar.loadXML("./dbManager.xml");
				
				contactsGrid = layout.cells("a").attachGrid();
				contactsGrid.setImagePath("<?=$codebase?>/imgs/");
				contactsGrid.setSkin("dhx_skyblue");
				contactsGrid.setHeader("ID,Name,Email,Address,City,State,Zip,Cell #,Home #,Birthdate");
				contactsGrid.setInitWidths("50,*,175,*,*,*,*,*,*,*");
				contactsGrid.setColAlign("center,left,left,left,left,left,left,left,left,left");
				contactsGrid.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
				contactsGrid.setColSorting("str,str,str,str,str,str,str,str,str,str");
				contactsGrid.attachHeader("#rspan,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter");
				contactsGrid.init();
				contactsGrid.load("./getContacts.php");
				
					
				
				
   				toolbar.attachEvent("onClick", function(id){   
											        // alert("Button "+id+" was clicked");
											        
											        if (id == "logOut") {
											        	//alert("Button "+id+" was clicked");
											        	//dhtmlxAjax.post("logout.php","");
											        	var loader = dhtmlxAjax.postSync("logout.php","");
											        	layout.unload();
											        	
											        	var dhxWin = new dhtmlXWindows();
											        	var win = dhxWin.createWindow("logout", 100, 200, 400, 175);
											        	dhxWin.window("logout").center();
											        	dhxWin.window("logout").setText("You have been Logged Out!");
											        	dhxWin.window("logout").attachURL("logout.html");
											        	
											        	
											        }
											        if (id == "refresh"){
											        	contactsGrid.clearAndLoad("./getContacts.php");
											        }
											        if (id == "viewProfile") {
											        	contactForm = layout.cells("b").attachForm();
											        	contactForm.loadStruct("./editProfile.xml");
											        	contactForm.load("./getCoInfo.php?id=" + MasterID);
											        	
											        
											        	/*
														var dpf = new dataProcessor("./updateCoDetails.php");
														dpf.init(contactForm);
														*/														
														
														contactForm.attachEvent("onButtonClick",function(id) {
																									
																									var PASS = contactForm.getItemValue("current_pass");
																									var P1 = contactForm.getItemValue("new_pass1");
																									var P2 = contactForm.getItemValue("new_pass2");
																									
																									
																									
																									if (PASS != "") {
																										if (P1 != P2) {
																											alert("New Passwords do not match.");
																										}
																										else {
																											checkPass(MasterID, PASS);
																										}
																									}
																									else {
																										contactForm.validate();
																									}
																									
																									
																									
																								})
																								
																	contactForm.attachEvent("onValidateError", function (input, value, result, label){
																											
																													var valWin = new dhtmlXWindows();
																													var newWin = valWin.createWindow("valWin", 100, 200, 400, 175);
																													valWin.window("valWin").center();
																													valWin.window("valWin").setText("Validation Error");
																													valWin.window("valWin").attachURL("valWin.html");
																																																		    
																										});
																																					
																	contactForm.attachEvent("onAfterValidate", function (status){
																													
																													if (status == true) {
																															contactForm.send("./updateCoDetails.php", "post");
																															contactForm.clear();
																															contactForm.load("./getCoInfo.php?id=" + MasterID);
																													}
																								});
																								
													}
													
													
											        
											            
											    });
											    
											    
				
				
				
									    
											    
											    
											    
											    
			    
			    
			})
   			
   			
   			
   			
   		</script>
   		
   		
   		
	</head>
	<body>
		
		
		
	</body>
</html>



				

Hi

myForm.send calls validate inside, that’s why onAfterValidate called in a loop.
you need to update your script:

contactForm.send("./updateCoDetails.php", “post”, callBack, true);

callBack - will called after script will get respone from server,
so you can do:
function callBack() {
contactForm.clear();
contactForm.load("./getCoInfo.php?id=" + MasterID);
}

4th “true” param will skip validation check in “send”