javascript 验证后如何提交表单

how to submit a form after validating by javascript

我在 php.I 中完成了一个注册页面,使用 javascript 执行了验证 我已经完成了验证,但我不知道将详细信息提交给下一个 page.This 的语法是我的代码我是 php 的新手,所以需要您的帮助。 提前谢谢你..对不起我的英语不好

register.php
    <!DOCTYPE html>
    <html>
    <head>
     <script>
    function validateForm() {

        var a = document.getElementById('n1').value;
        if(a==""){
        alert("please enter your name");
        return false;
        }
        var b = document.getElementById('u1').value;
        if(b==""){
        alert("please enter the username");
        return false;
        }
        var p3 = document.getElementById('p1').value;
        if(p3==""){
        alert("please enter the password");
        return false;
        }

        var p4 = document.getElementById('p2').value;
        if(p4==""){
        alert("please enter the confirmation password");
        return false;
        }

         //if(p3.value!=p4.value){
         //alert("hh");
         //alert("Passwords do no match");
         //return false;
        //}else{
        //return true;
        //}

          var c = document.getElementById('a1').value;
            if(c==""){
        alert("please enter your address");
        return false;
        }
          var d = document.getElementById('ph').value;
        if(d==""){
        alert("please enter your phone no:");
        return false;
        }
    (48)    document.registrationform.submit;


    }
    </script>
    </head>
    <body>
    <form action ="#" name="registrationform" id=="formid" class="formclass" action="registerbackend.php" method ="post" >
    name    :<input type="text" id="n1" name="name"><br><br>
    username:<input type="text" id="u1" name="username"><br><br>
    password:<input type="password" id="p1" name="password"><br><br>
    confirm password:<input type="password" id="p2" name="password2"><br><br>
    Address   :<textarea name="address" id= "a1"rows="4" cols="40"></textarea><br><br>
    phone   :<input id="ph" type="numbers" name="phone"><br><br>
 (62)   <input  type="button" name="register" onclick="validateForm()" value="Register">
    <a href="login.php"><input id="button"  type="button"  value="cancel"> </a>
    </form>
    </body>
    </html>

使用这个:-

document.getElementById("formid").submit();

改变这个:-

document.registrationform.submit;

对此:-

document.getElementById("formid").submit();

尝试使用以下代码提交表单

document.getElementById("formid").submit();
**change this :-**
 <form action ="#" name="registrationform" id=="formid" class="formclass" action="registerbackend.php" method ="post" >
**to this:->**
 <form action ="#" name="registrationform" id="formid" class="formclass" action="registerbackend.php" method ="post" >
**change your javascript code to:**
 function validateForm() {
   var status="true";
        var a = document.getElementById('n1').value;
        var b = document.getElementById('u1').value;
        var p4 = document.getElementById('p2').value;
        var c = document.getElementById('a1').value;
        var d = document.getElementById('ph').value;
        var p3 = document.getElementById('p1').value;
        if(a==""){
        alert("please enter your name");
        status="false";
        }        
        else if(b==""){
        alert("please enter the username");
                status="false";
        }       
        else if(p3==""){
        alert("please enter the password");
        status="false";
        }        
        else if(p4==""){
        alert("please enter the confirmation password");
        status="false";
        }
        else if(c==""){
        alert("please enter your address");
        status="false";
        }          
        else if(d==""){
        alert("please enter your phone no:");
        status="false";
        }
       if(status=="true"){
     document.getElementById("fromid").submit();
}
}

您的表单提交语法错误。

改变这个

document.registrationform.submit;

对此:

document.getElementsByTagName("form")[0].submit();