Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Does Not send form

    Hello there. I want to send a form to the next one but it seems my javascript is interupting or something. can samome help me a bit here ??

    here is my code the problem is , it does not redirect to the next page step2.php

    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <LINK href="mycss.css" rel="stylesheet" type="text/css">
    
    <title>Home Page </title>
    <?php
    session_start();
    ?> 
    <script>
    	function formSubmit()
    	{
    	//Clears All the error messages. so they can be reprinted 
    	//or show that evrything is correct
    	 	var node = document.getElementById("wrongpass")
    		node.innerHTML =""
    	 	var node = document.getElementById("noname")
    		node.innerHTML =""
        	var node = document.getElementById("nolastname")
    		node.innerHTML =""
    	//Xpass is a valitation variable where it INC when it sees a correct field
    	//if its 3 it will accept the form and send the client to next page with 
    	//The Login Information
    		var xpass = 0 ; 
    		
    //The Following if satements wil check if the user added correct info in the form		
     	if  ( document.getElementById("pass").value == 5 )  
     		{
      			xpass = xpass +1 ; 
     		}
     	else
      		{ 
    			document.getElementById("wrongpass").innerHTML = "Correct Password";
    		 	document.getElementById("wrongpass").innerHTML = "You Have Entered A wrong <b>Password</b> (Its 5)";
    
    		}
    
     	if  ( document.getElementById("lastname").value == "" )
    	 	{
        	document.getElementById("nolastname").innerHTML = "You Did Not Enter A <b>Last Name</b>";
     		}
        else 
     		{
      			xpass = xpass +1 ;
     		}
     
        if  ( document.getElementById("firstname").value == "" ) 
    		{
      		 document.getElementById("noname").innerHTML = "You Did Not Enter A Name";
       
     		}
       else 
     		{
      			xpass = xpass +1 ;
     		}
     
    		if ( xpass == 3) {
    
    		}
    
    	else { 
        alert("Check The Info Given to you to know whats wrong"); 
    	}
    
    }
    
    
    </script>
    
    </head>
    
    <body>
    	<div id="page-wrap">
    		<h1>Welcome Please Login </h1>
    		<p id="wrongpass"></p> 
    		<p id="noname"></p> 
    		<p id="nolastname"></p> 
    
    	<div id="contact-area">
    	<form  action="step2.php" method="get" id="login" > 
    		First name: <input type="text" class="contactform" name="fname" id="firstname"><br> 
    		Last name: <input type="text" name="lname" id="lastname"><br>
    		Password :  <input type="password" name="pass" id = "pass"  > <br><br>
    		<input type="button" onclick="formSubmit()" value="Submit"> 
    	</form>
    	</div>
    	</div> 
    
    </body>
    </html>

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Your code isn't preventing the submission of the form, because it isn't capable of doing that.

    Nothing on that page instructs the form to submit.

    You need <input type="submit">

    You need to attach your function to the onsubmit event, and on error it must return false.

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    With the DOCTYPE you are using you should close certain tags with />

    Code:
    <link href="mycss.css" rel="stylesheet" type="text/css" />
    This includes input tags, and <br> should be <br /> - or switch to HTML5

    It is preferable to use a submit button, rather than an input-button:

    Code:
    <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
    Your formSubmit() function should be called in the onsubmit event of the form, otherwise it will not be called if someone just presses Enter:

    Code:
    <form  action="step2.php" method="get" id="login" onsubmit="formSubmit();">
    Your formSubmit() code needs to return false; if you wish to prevent the form-submission.

    You should ideally test against '5' rather than the number 5, as form-values are strings:

    Code:
    if  ( document.getElementById("pass").value == '5' )
    BTW I would prefer not to use the variable name 'node', but that's just me!
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Demeteor (01-10-2013)

  • #4
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks both of you for the great help. I was wondering Why I had to insert that many else
    in the code. I also forgot to do
    Code:
      document.getElementById("login").submit()
    so it will send the form to step2.php
    now it sends it correctly. one more question

    to check if the user entering step2.php and step3.php has entered the password correctly I need php right ? if so what is the way of doing it ? If you can help with this one it would be great

  • #5
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Demeteor View Post
    I also forgot to do
    Code:
      document.getElementById("login").submit()
    That is something you MUST forget. Never call submit, use a submit-type button as you were told.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •