This project source code will teach you how to validate forms. Each field in the registration form has its own validation which is the First Name and Last Name has a null or empty validation. These validations will check if the fields are not empty or null. For the Email, upon submitting the registration form the system will check if the value entered in the Email field is a valid email. Then for the Password, the system will check if the entered characters length in this field is at least 8 characters. Lastly, the Confirm Password will check if the entered value in Password Field is identical equals to the value of this field. Using the Confirm Password validation will help the user to ensure that the password he/she entered is correct since the characters in the Password Field is not readable.
<form method="post" action="index.php"> <table> <tr> <td colspan="2"> <!-- This PHP script is will display the success message of the registration --> <?php if(isset($successful)){ echo $successful; } ?> </td> </tr> <tr> </tr> <tr> <td> <!-- This PHP script will display when the form is submitted in First Name field is empty --> <?php if(isset($errors['fname'])){echo "<h2>" .$errors['fname']. "</h2>"; } ?> </td> <td> <!-- This PHP script will display when the form is submitted in Last Name field is empty --> <?php if(isset($errors['lname'])){echo "<h2>" .$errors['lname']. "</h2>"; } ?> </td> </tr> <tr> <!-- The PHP Script in value attribute of the input below is use for value retrieval when registration fails due to validations --> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> </table> </form>
<?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $errors['fname'] = "* First Name is required."; } $errors['lname'] = "* Last Name is required."; } $errors['email'] = "* Not a valid e-mail address."; } $errors['password'] = "* Password Must Contain at least 8 Chanacters."; } $errors['confirm_password'] = "* Password do not much."; } function createSalt(){ } $salt = createSalt(); if($num_row >= 1){ $errors['email'] = "Email address is unavailable."; }else{ $sql = "INSERT INTO members(`fname`, `lname`, `email`, `salt`, `password`) VALUES ('$fname', '$lname', '$email', '$salt', '$password')"; $_POST['fname'] = ''; $_POST['lname'] = ''; $_POST['email'] = ''; $successful = "<h3> You are successfully registered.</h3>"; } } } ?>
Download the source code by clicking the "Download" button below this article for the complete source code of this simple Registration Form Validation.
I hope this will help you. Enjoy Coding :)
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.