Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(empty($_POST['firstname'])){
- $error['firstname'] = 'Firstname is empty!';
- }
- if(empty($_POST['lastname'])){
- $error['lastname'] = 'Lastname is empty!';
- }
- if(empty($_POST['email'])){
- $error['email'] = 'Email is empty!';
- }
- if(empty($_POST['password'])){
- $error['password'] = 'Password is empty!';
- }
- if(empty($_POST['password-confirm'])){
- $error['password-confirm'] = 'Password and password confirmation not match!';
- }
- if(empty($_POST['password-confirm'])){
- $error['password-confirm'] = 'Password confirmation is empty!';
- }
- if(!empty($_POST['password-confirm']) && !empty($_POST['password']) ){
- if($_POST['password-confirm'] == $_POST['password']){
- $error['password-confirm'] = 'Password confirmation and password is not match!';
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title>Form Validation</title>
- <link rel="stylesheet" href="css/bootstrap.min.css">
- <link rel="stylesheet" href="css/fontawesome-all.min.css">
- </head>
- <body>
- <div class="container py-5">
- <div class="col-8 offset-2">
- <h1>Form Validation</h1>
- <form action="" method="post">
- <div class="form-group">
- <label for="firstname">First Name</label>
- <input type="text" name="firstname" id="firstname" class="form-control" autofocus placeholder="First Name">
- <?php if(!empty($_POST) && !empty($error['firstname'])): ?>
- <div class="alert alert-danger" role="alert">
- <?php echo $error['firstname'] ?>
- </div>
- <?php endif; ?>
- </div>
- <div class="form-group">
- <label for="lastname">Last Name</label>
- <input type="text" name="lastname" id="lastname" class="form-control" placeholder="Last Name">
- <?php if(!empty($_POST) && !empty($error['lastname'])): ?>
- <div class="alert alert-danger" role="alert">
- <?php echo $error['lastname'] ?>
- </div>
- <?php endif; ?>
- </div>
- <div class="form-group">
- <label for="email">Email</label>
- <input type="email" name="email" id="email" class="form-control" placeholder="Email">
- <?php if(!empty($_POST) && !empty($error['email'])): ?>
- <div class="alert alert-danger" role="alert">
- <?php echo $error['email'] ?>
- </div>
- <?php endif; ?>
- </div>
- <div class="form-group">
- <label for="password">Password</label>
- <input type="password" name="password" id="password" class="form-control" placeholder="Password">
- <?php if(!empty($_POST) && !empty($error['password'])): ?>
- <div class="alert alert-danger" role="alert">
- <?php echo $error['password'] ?>
- </div>
- <?php endif; ?>
- </div>
- <div class="form-group">
- <label for="password-confirm">Password Confirmation</label>
- <input type="password" name="password-confirm" id="password-confirm" class="form-control" placeholder="Password Confirmation">
- <?php if(!empty($_POST) && !empty($error['password-confirm'])): ?>
- <div class="alert alert-danger" role="alert">
- <?php echo $error['password-confirm'] ?>
- </div>
- <?php endif; ?>
- </div>
- <button class="btn btn-info">Send</button>
- </form>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement