Advertisement
Guest User

Untitled

a guest
May 5th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.53 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <head>
  3. <title>Form validation </title>
  4. </head>
  5. <body>
  6. <?php
  7. if (isset($_POST['submit'])) {
  8. ////////////////////////////////////////////////////////////////////
  9. //checking names
  10. ///////////////////////////////////////////////////////////////////
  11.  
  12. if(empty($_POST['fname']))
  13. $msg_fname = "You must supply your forname";
  14. $fname_sub = $_POST['fname'];
  15. $regexf = '/^[a-zA-Z ]*$/';
  16. preg_match($regexf, $fname_sub, $fname_matches);
  17. if(!$fname_matches[o])
  18. $msg2_fname = "please check forname";
  19.  
  20. ///////////////////////////////////////////////////////////////////
  21.  
  22. if(empty($_POST['lname']))
  23. $msg_lname = "You must supply your surname";
  24. $lname_sub = $_POST['lname'];
  25. $regexl= '/^[a-zA-Z ]*$/';
  26. preg_match($regexl, $lname_sub, $lname_matches);
  27. if(!$lname_matches[o])
  28. $msg2_lname = "please check surname";
  29.  
  30. ////////////////////////////////////////////////////////////////////
  31. //check email
  32. ////////////////////////////////////////////////////////////////////
  33.  
  34. if(empty($_POST['email']))
  35. $msg_email = "You must supply your email";
  36. $email_sub = $_POST['email'];
  37. $email_pattern = '/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/';
  38. preg_match($email_pattern, $email_sub, $email_matches);
  39. if(!$email_matches[0])
  40. $msg2_email = "Must be of valid email format";
  41.  
  42.  
  43.  
  44. }
  45. ?>
  46.  
  47. <?php
  48. // validation complete
  49. if(isset($_POST['submit'])){
  50. if($msg_fname=="fname" && $msg2_fname=="fname" && $msg_lname=="lname" && $msg2_lname=="lname" && $msg_email=="" &&  $msg2_email=="");
  51. $msg_success = "You filled this form up correctly";
  52. }
  53. ?>
  54. <div class="container">
  55. <?php echo "<h3 class='success_msg'>".$msg_success."</h3>"; ?>
  56. <form id="registration_form" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  57.  
  58.   <label>Forename<span class="note">*</span>:</label>
  59.   <input type="text" name="fname"  value="<?php echo $_POST['fname']; ?>">  
  60.   <?php echo "<p class='note'>".$msg_fname."</p>";?>
  61.   <?php  //echo "<p class='note'>".$msg2_fname."</p>";?>
  62.    
  63.     <label>Surname<span class="note">*</span>:</label>
  64.   <input type="text" name="lname"  value="<?php echo $_POST['lname']; ?>">  
  65.   <?php echo "<p class='note'>".$msg_lname."</p>";?>
  66.   <?php //echo "<p class='note'>".$msg2_lname."</p>";?>
  67.  
  68.   <label>Email address<span class="note">*</span>:</label>
  69.   <input type="text" name="email" value="<?php echo $_POST['email']; ?>">
  70.    <?php echo "<p class='note'>".$msg_email."</p>";?>
  71.   <?php echo "<p class='note'>".$msg2_email."</p>";?>
  72.    
  73.   <button type="submit" class="" name="submit">send</button>
  74. </form>
  75. </div>
  76. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement