jimmyt1988 Posted November 22, 2010 Share Posted November 22, 2010 registration.validate() is called. var registration = { flushErrors: function(){ $('form[name=registrationForm] .error').html(""); this.errorCollection = []; this.errorMessage = ""; this.validationCollection = []; this.validationErrorMessage = ""; this.progress = true; }, sanitiseField: /([A-Za-z0-9\_\-\.])$/, usernameMinimumChar: 5, passwordMinimumChar: 6, errorColour: "#F46C38", errorNotificationType: "border-color", errorCollection: [], errorMessage: "", errorPrefix: "Please fill in the following missing fields: ", validationCollection: [], validationErrorMessage: "", validatedColour: "#F0F0F0", progress: true, ajaxCall: function(process, obj, type){ $.post("registration-post.php", type + "=" + process + "&check=1", function(data){ var returnedValue = $.trim(data); if(returnedValue==""){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ //1 alert(returnedValue); registration.validationCollection.push(String(returnedValue)); //$('.error').append(returnedValue + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; } } ); }, emailValidation: function(email, obj, type){ var filter = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if(!filter.test(email)){ this.validationCollection.push("The email address you have entered does not seem to be a valid entry"); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } this.ajaxCall(email, obj, type); }, usernameValidation: function(username, obj, type){ if(!this.sanitiseField.test(username)){ this.validationCollection.push("Your username must only contain (A-Z, a-z, 0-9, _, -, .). Please try again."); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } if(username.length < this.usernameMinimumChar){ this.validationCollection.push("Your username must contain atleast " + this.usernameMinimumChar + " characters"); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } this.ajaxCall(username, obj, type); }, passwordValidation: function(password, obj){ if(!this.sanitiseField.test(password)){ this.validationCollection.push("Your password must only contain (A-Z, a-z, 0-9, _, -, .). Please try again."); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } if(password.length < this.passwordMinimumChar){ this.validationCollection.push("Your password must contain atleast " + this.passwordMinimumChar + " characters"); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); if(password!=$('#registerUser input[name=confirmPassword]').val()){ this.validationCollection.push("Your confirmation password does not match your chosen password"); $($('#registerUser input[name=confirmPassword]').val()).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $($('#registerUser input[name=confirmPassword]').val()).css(registration.errorNotificationType, registration.validatedColour); } } }, validate: function(){ this.flushErrors(); $('#registerUser input[type=text], #registerUser input[type=password]').each( function(){ if($(this).val() == ""){ $(this).css(registration.errorNotificationType, registration.errorColour); //registration.errorCollection.push($(this).parent().prev().text().replace(": ", "")); registration.errorCollection.push($(this).parent().prev().text()); registration.progress = false; }else{ switch($(this).attr("name")){ case "email": registration.emailValidation($(this).val(), $(this), $(this).attr("name")); break; case "username": registration.usernameValidation($(this).val(), $(this), $(this).attr("name")); break; case "password": registration.passwordValidation($(this).val(), $(this)); break; default: $(this).css(registration.errorNotificationType, registration.validatedColour); } } } ); if(this.progress){ return this.progress; }else{ for (var i=0; i<this.errorCollection.length; i++){ if(i==(this.errorCollection.length)-1){ this.errorMessage += this.errorCollection; }else{ this.errorMessage += this.errorCollection + ", "; } } //2 alert(""); for (var i=0; i<this.validationCollection.length;i++){ if(i==(this.validationCollection.length)-1){ this.validationErrorMessage += this.validationCollection; }else{ this.validationErrorMessage += this.validationCollection + "<br />"; } } if(this.errorMessage == ""){ $('form[name=registrationForm] .error').html(this.validationErrorMessage); }else{ $('form[name=registrationForm] .error').html(this.errorPrefix + this.errorMessage + "<br />" + this.validationErrorMessage); } } return this.progress; } } 1st red highlighted code: the alert returns "The email you have entered is already registered. Please try another!". I push it into an array... 2nd red highlighted code: If i do not call an alert just before itterating through my array, the array contains nothing.. If I itterate through it just after an alert(""); the array works fine. explain Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted November 22, 2010 Author Share Posted November 22, 2010 I think its safe to say that the ajax call is taking its sweet time. The alert must give it that extra pause that it requires. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 22, 2010 Share Posted November 22, 2010 I suspect it is because your AJAX call is asynchronous? Not sure since I'm not going to try and decypher a 100 lines of code to understand what is calling what. The fact that you are putting in an alert gives enough time for the asynchonous process to complete before that block of code is executed. Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted November 23, 2010 Author Share Posted November 23, 2010 Im looking at the callbacks now for the ajax. Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted November 23, 2010 Author Share Posted November 23, 2010 Any ideas of simulating an ajax callback. Only when the information comes back or fails should it continue through my functions? Perhaps i'm too tired. i guess ill have a sleep soon. Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted November 23, 2010 Author Share Posted November 23, 2010 YEHAAAAAAA WOOPEEEEE WIPPEEEEEe, YIPPEEE DOO DAAAAAA, YIPPEEEDEE DAYYY... $.ajax({ type: "POST", url: "registration-post.php", data: type + "=" + process + "&check=2", async: false, success: function(data){ var returnedValue = $.trim(data); if(returnedValue=="ok"){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ registration.validationCollection.push(returnedValue); //$('.error').append(returnedValue + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; alert(registration.progress); } } }); async: false LOLLLLLL!!!! OMG everything just works perfect.. YEHAAAAAA, finit! 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.