how to submit a form after validating by javascript

时间:2015-11-12 11:40:24

标签: php phpmyadmin

I have done a registration page in php.I performed validation using javascript I have done the validation but i dont know the syntax for submitting the details to next page.This is my code i am a very new beginner to php so need your help. Thank you in advance..sorry for my poor english

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>

4 个答案:

答案 0 :(得分:0)

Use this :-

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

change this :-

document.registrationform.submit;

to this :-

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

答案 1 :(得分:0)

Try the below code for submitting the form

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

答案 2 :(得分:0)

**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();
}
}

答案 3 :(得分:0)

Your form submission syntax is wrong.

Change this

document.registrationform.submit;

to this:

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