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>
1

4 Answers 4

0

Your form submission syntax is wrong.

Change this

document.registrationform.submit;

to this:

document.getElementsByTagName("form")[0].submit();
Sign up to request clarification or add additional context in comments.

1 Comment

yes i did it.I didn't reached 15 reputations so please upvote my question it will be displayed with in 2 days.. :-)
0

Try the below code for submitting the form

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

4 Comments

still getting below error while trying this code.Uncaught TypeError: Cannot read property 'submit' of null.alidateForm @ register.php:48onclick @ register.php:62
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
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.
If you found my question is worth..please upvote my question
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();
}
}

Comments

0

Use this :-

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

change this :-

document.registrationform.submit;

to this :-

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

3 Comments

while using the above code am getting error message from chrome browser. Uncaught TypeError: Cannot read property 'submit' of nullvalidateForm @ register.php:48onclick @ register.php:62
document.getElementById("formid").submit();
I've tried it am getting error in two places.that is mentioned as 48 and 62 in the above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.