Guest User

Untitled

a guest
Mar 9th, 2018
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="jquery.js"></script>
  4. <script>
  5. $(document).ready( function() {
  6. $("#target").submit( function(event) {
  7. //We will initialize a variable so that we can contain all error messages on a single alert box.
  8. var errorMessage = "";
  9. if($(".requiredFirstname").val() == "")
  10. {
  11. errorMessage = errorMessage + "Please fill in the firstname\n";
  12. //This code is used so that the page won't be submitted if there are errors.
  13. event.preventDefault();
  14. }
  15. if($(".requiredLastname").val() == "")
  16. {
  17. errorMessage = errorMessage + "Please fill in the lastname\n";
  18. //This code is used so that the page won't be submitted if there are errors.
  19. event.preventDefault();
  20. }
  21.  
  22. //This code checks wheter the errorMessage variable contains error messages
  23. if (errorMessage != "")
  24. {
  25. alert(errorMessage);
  26. }
  27. });
  28. });
  29. </script>
  30. </head>
  31. <body>
  32. <?php
  33. $firstname = "";
  34. $middlename = "";
  35. $lastname = "";
  36. $password = "";
  37. $username = "";
  38. if(isset($_POST['firstname'])) {
  39. $firstname = $_POST['firstname'];
  40. $middlename = $_POST['middlename'];
  41. $lastname = $_POST['lastname'];
  42. $password = $_POST['password'];
  43. $username = $_POST['username'];
  44.  
  45. //Place the code for insert sql query here
  46. echo "You have successfully added a record!";
  47. }
  48.  
  49. ?>
  50. <form id="target" method="post" action="index.php">
  51. Firstname*: <input class="requiredFirstname" type="text" name="firstname" value="<?php echo $firstname; ?>"><br/>
  52. Middlename*: <input type="text" name="middlename" value="<?php echo $middlename; ?>"><br/>
  53. Lastname*: <input class="requiredLastname" type="text" name="lastname" value="<?php echo $lastname; ?>"><br/>
  54. Username* <input class="requiredUsername" type="text" name="username" value="<?php echo $username; ?>"><br/>
  55. Password: <input type="password" name="password" value="<?php echo $password; ?>"><br/>
  56. <input type="submit" />
  57. </form>
  58. </body>
  59. </html>
Add Comment
Please, Sign In to add comment