2

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>
vimal kumar
  • 75
  • 1
  • 8
  • 1
    Possible duplicate of [submit the form using ajax](http://stackoverflow.com/questions/13611614/submit-the-form-using-ajax) – Szabolcs Páll Nov 12 '15 at 12:02

4 Answers4

0

Use this :-

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

change this :-

document.registrationform.submit;

to this :-

document.getElementById("formid").submit();
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
0

Try the below code for submitting the form

document.getElementById("formid").submit();
AeJey
  • 1,447
  • 20
  • 40
  • still getting below error while trying this code.Uncaught TypeError: Cannot read property 'submit' of null.alidateForm @ register.php:48onclick @ register.php:62 – vimal kumar Nov 12 '15 at 11:51
  • could you please update the question with the error you get and the codes on line 48 and 63 so that we can check and provide you the solution – AeJey Nov 12 '15 at 12:01
  • i have found the solution.its because of the wrong syntax used in the submit.Rajdeep Paul provided me the write syntax see it above. – vimal kumar Nov 12 '15 at 12:51
  • If you found my question is worth..please upvote my question – vimal kumar Nov 12 '15 at 12:52
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();
}
}
Alina Anjum
  • 1,178
  • 6
  • 30
  • 53
0

Your form submission syntax is wrong.

Change this

document.registrationform.submit;

to this:

document.getElementsByTagName("form")[0].submit();
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37
  • yes i did it.I didn't reached 15 reputations so please upvote my question it will be displayed with in 2 days.. :-) – vimal kumar Nov 12 '15 at 12:49