0

Hi all,

I have a issue that I have been try to solve for a long time...

Background info
I have a form that when submitted, checks validation and also does an ajax request to see if user email exists.
Validation is working, and email checking is also working. The only issue is when everything is fine, the form will not submit.

For some strange reason, the 'return true' is not passing true value to submit form....

I cant understand what the issue is. Starting to get intimidated :/

Help would be highly appreciated.

<form name="newuser" id="form" method="post" action="do_new_user.php" onSubmit="return validateForm(false)"> 


function validateForm(submitNow){




if (submitNow == true){
         alert ('call ok');
     return true;
     }

else
{
    var x=document.forms["newuser"]["name"].value;
    var x2=document.forms["newuser"]["surname"].value;
    var x3=document.forms["newuser"]["email"].value;
    var x4=document.forms["newuser"]["password1"].value;
    var x5=document.forms["newuser"]["password2"].value;

    if (x==null || x=="") 
      {

      $("#form_status").fadeIn("slow");
      $("#form_status").text("Please enter your name.");
      return false;
      }

    if (x2==null || x2=="") 
      {
      $("#form_status p").fadeIn("slow");
      $("#form_status").text("Please enter your surname.");
      return false;
      }

    if (x3==null || x3=="") 
      {
      $("#form_status").fadeIn("slow");
      $("#form_status").text("Please enter your email address.");
      return false;
      } 

    var atpos=x3.indexOf("@");
    var dotpos=x3.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x3.length)
      {
      $("#form_status").fadeIn("slow");
      $("#form_status").text("Email address in invalid.");
      return false;
      }

    if (x4==null || x4=="") 
      {
      $("#form_status").fadeIn("slow");
      $("#form_status").text("Please enter your password.");
      return false;
      }   

    if (x5==null || x5=="") 
      {
      $("#form_status").fadeIn("slow");
      $("#form_status").text("Please re-enter your password.");
      return false;
      } 

    if (x4!==x5)
      {
      $("#form_status").fadeIn("slow");
      $("#form_status").text("Password Mismatch.");
      return false; 
      }

    //Check if username exists.
    $.post("/check_user_exists.php",  
             {
                x3 : x3
             } , 

             function(data)
              { 

                var obj = jQuery.parseJSON(data);

                if (obj.email_exists == 1) 
                  {   
                    $("#form_status").fadeIn("slow");
                    $("#form_status").text("Email Address Taken.");

                }  

                if (obj.email_exists == 2)   
                  {   
                $("#form_status").fadeIn("slow");
                    $("#form_status").text("Email ok.");
                    validateForm(true);
                  }  
    });
     return false; 
}


}
2
Contributors
4
Replies
20
Views
3 Years
Discussion Span
Last Post by iamthwee
0

Hi, I got your email.

Unfortunately, I can't be of much help because I would need to see the html and your php.

If you could zip them up and attach to email that would help.

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.