Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/javascript" src="jquery.js"></script>
- <script>
- $(document).ready( function() {
- $("#target").submit( function(event) {
- //We will initialize a variable so that we can contain all error messages on a single alert box.
- var errorMessage = "";
- if($(".requiredFirstname").val() == "")
- {
- errorMessage = errorMessage + "Please fill in the firstname\n";
- //This code is used so that the page won't be submitted if there are errors.
- event.preventDefault();
- }
- if($(".requiredLastname").val() == "")
- {
- errorMessage = errorMessage + "Please fill in the lastname\n";
- //This code is used so that the page won't be submitted if there are errors.
- event.preventDefault();
- }
- //This code checks wheter the errorMessage variable contains error messages
- if (errorMessage != "")
- {
- alert(errorMessage);
- }
- });
- });
- </script>
- </head>
- <body>
- <?php
- $firstname = "";
- $middlename = "";
- $lastname = "";
- $password = "";
- $username = "";
- if(isset($_POST['firstname'])) {
- $firstname = $_POST['firstname'];
- $middlename = $_POST['middlename'];
- $lastname = $_POST['lastname'];
- $password = $_POST['password'];
- $username = $_POST['username'];
- //Place the code for insert sql query here
- echo "You have successfully added a record!";
- }
- ?>
- <form id="target" method="post" action="index.php">
- Firstname*: <input class="requiredFirstname" type="text" name="firstname" value="<?php echo $firstname; ?>"><br/>
- Middlename*: <input type="text" name="middlename" value="<?php echo $middlename; ?>"><br/>
- Lastname*: <input class="requiredLastname" type="text" name="lastname" value="<?php echo $lastname; ?>"><br/>
- Username* <input class="requiredUsername" type="text" name="username" value="<?php echo $username; ?>"><br/>
- Password: <input type="password" name="password" value="<?php echo $password; ?>"><br/>
- <input type="submit" />
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment