Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if($_POST)
- {
- $errors = array();
- //start validations
- if(empty($_POST['firstName']))
- {
- $errors['firstName1'] = "Your first name needs to be completed";
- }
- if(empty($_POST['lastName']))
- {
- $errors['lastName1'] = "Your last name needs to be completed";
- }
- if(empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
- {
- $emailErr = "Invalid email format";
- $errors['email1'] = "Invalid email format";
- }
- if(empty($_POST['phoneNumber']))
- {
- $errors['phoneNumber1'] = "Your phone number needs to be completed";
- }
- if(empty($_POST['choice']))
- {
- $errors['choice1'] = "You have to do a choice";
- }
- if(empty($_POST['msg']))
- {
- $errors['msg1'] = "Your message needs to be completed";
- }
- //check errors
- if(count($errors) == 0)
- {
- //success page
- header("Location: success.php");
- exit();
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Form !</title>
- </head>
- <body>
- <form action="form.php" method="post" target="">
- <h2 class="title">Contact us</h2>
- <div>
- <label for="firstName">First name </label>
- <input type="text" placeholder="Hugo" name="firstName" id="firstName" value="<?php if(isset($_POST['firstName'])) echo $_POST['firstName']; ?>" required/>
- </div>
- <p><?php if(isset($errors['firstName1'])) echo $errors['firstName1']; ?></p>
- <div>
- <label for="lastName">Last name </label>
- <input type="text" placeholder="Gehl" name="lastName" id="lastName" value="<?php if(isset($_POST['lastName'])) echo $_POST['lastName']; ?>" required/>
- </div>
- <p><?php if(isset($errors['lastName1'])) echo $errors['lastName1']; ?></p>
- <div>
- <label for="email">Email </label>
- <input type="email" placeholder="hugogehl@exemple.com" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" required/>
- </div>
- <p>
- <style>
- p {
- color: red;
- }
- </style>
- <?php if(isset($errors['email1'])) echo $errors['email1']; ?>
- </p>
- <div>
- <label for="phoneNumber">Phone number </label>
- <input type="tel" placeholder="0625234595" name="phoneNumber" id="phoneNumber" value="<?php if(isset($_POST['phoneNumber'])) echo $_POST['phoneNumber']; ?>" required pattern="^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$"/>
- </div>
- <p><?php if(isset($errors['phoneNumber1'])) echo $errors['phoneNumber1']; ?></p>
- <div>
- <label for="choice">Do your choice</label>
- <select id="choice" name="choice" required>
- <option value="">-- Do your choice --</option>
- <option value="Subject one">Subject one</option>
- <option value="Subject two">Subject two</option>
- <option value="Subject three">Subject three</option>
- </select>
- </div>
- <p><?php if(isset($errors['choice'])) echo $errors['choice1']; ?></p>
- <div>
- <label for="msg">Message </label>
- <textarea placeholder="Your message" id="msg" name="msg" required></textarea>
- </div>
- <p><?php if(isset($errors['msg1'])) echo $errors['msg1']; ?></p>
- <div class="button">
- <button type="submit" value="submit">Send !</button>
- </div>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement