I searched for a simple script which validates a html-form and if everything is alright submit the form to a php script ... i didn't really find something so here is a simple one of mine

1st - create your form with the js-validation

  1. <form action="server.php" <brbr=""> onsubmit="return k_checkForm(this);"   
  2.  method="post">  
  3. Name: <input type="text" name="name">  
  4. Number: <input type="text" name="phone">  
  5. <input type="submit">  
  6. </form>  

2nd - put a validation js somewhere in the html file (preferable in the head section)
  1. <script language="JavaScript" type="text/javascript">  
  2.   function k_checkForm(form) {  
  3.  var name=form.name.value;  
  4.  var phone_number = form.phone.value;  
  5.    
  6.  if (name == "") {  
  7.   alert ("Please enter your name ...");  
  8.   return false;  
  9.  }   
  10.      
  11.  if (phone_number == "") {  
  12.   alert("Please enter your phone number ...");  
  13.   return false;  
  14.  }  
  15.         
  16.  return true;  
  17. }  
  18. </script>  


3nd - php-script (server.php) here you can access the variables like this
  1. echo $_POST["name"];   
  2. echo $_POST["phone"];  

Related Posts by Categories



Widget by Hoctro | Jack Book