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; 
}


}
Member Avatar for iamthwee

Not checked it but line 99 return false looks out of place?

When removing this, email passes validation even if it exists...

Member Avatar for iamthwee

Don't you need a success function in your jquery?

Member Avatar for iamthwee

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.