Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Small PHP Form Validation</title>
- <style>
- .error{color:red}
- </style>
- </head>
- <body>
- <?php
- if(isset($_POST['form1'])) {
- $u_name = $_POST['u_name'];
- $u_email = $_POST['u_email'];
- $u_username = $_POST['u_username'];
- $u_password = $_POST['u_password'];
- $valid=1;
- if(empty($u_name)) {
- echo "<div class='error'>Your name Can't be Empty</div><br>";
- $valid = 0;
- }
- if(empty($u_email)) {
- echo "<div class='error'>Your Email Can not be Empty</div><br>";
- $valid = 0;
- }
- if(empty($u_username)) {
- echo "<div class='error'>Username Can not be Empty</div><br>";
- $valid = 0;
- }
- if(empty($u_password)) {
- echo "<div class='error'>Password Can not be Empty</div><br>";
- $valid = 0;
- }
- if(!(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $u_email))) {
- echo "<div class='error'>Email Not Valid. Please Enter Valid Email Address</div>";
- $valid = 0;
- }
- if($valid == 1) {
- echo "Success";
- }
- else {
- echo "Wrong";
- }
- }
- else{?>
- <form action="" method="post">
- <table>
- <tr>
- <td>Name: </td>
- <td><input type="text" name="u_name" placeholder="Full Name" /></td>
- </tr>
- <tr>
- <td>Email Address: </td>
- <td><input type="text" name="u_email" placeholder="Email Address" ></td>
- </tr>
- <tr>
- <td>Username: </td>
- <td><input type="text" name="u_username" placeholder="Username" /></td>
- </tr>
- <tr>
- <td>Password: </td>
- <td><input type="password" name="u_password" placeholder="Password" /></td>
- </tr>
- <tr>
- <td><input type="submit" value="SEND" name="form1"/></td>
- </tr>
- </table>
- <body>
- </html>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement