Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $nameError = '';
- $firstNameError = '';
- $emailError = '';
- $phoneError = '';
- $subjectError = '';
- $messageError = '';
- if (isset($_POST['isFormSubmitted']))
- {
- $name = $_POST['name'];
- $firstName = $_POST['firstName'];
- $email = $_POST['email'];
- $phone = $_POST['phone'];
- $subject = $_POST['subject'];
- $message = $_POST['message'];
- if (empty($name) === true)
- {
- $nameError = '<br> Erreur : champ invalide';
- }
- if (empty($firstName) === true)
- {
- $firstNameError = '<br> Erreur : champ invalide';
- }
- if (empty($email) === true)
- {
- $emailError = '<br> Erreur : champ invalide';
- }
- if (empty($phone) === true)
- {
- $phoneError = '<br> Erreur : champ invalide';
- }
- if (empty($subject) === true)
- {
- $subjectError = '<br> Erreur : champ invalide';
- }
- if (empty($message) === true)
- {
- $messageError = '<br> Erreur : champ invalide';
- }
- $variable = filter_var( $email,FILTER_VALIDATE_EMAIL);
- if ($variable === false)
- {
- $emailError = 'Bad email';
- }
- if (
- empty($nameError) === true && empty($firstNameError) === true && empty($emailError) === true &&
- empty($subjectError) === true && empty($messageError) === true && empty($phoneError) === true
- )
- {
- header("Location: hello.php");
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="fr">
- <head>
- <meta charset="UTF-8">
- <title>Formulaire PHP</title>
- <meta name="">
- </head>
- <body>
- <form action="index.php" method="post">
- <p>
- <label for="name">Nom :*</label>
- <input type="text" id="name" name="name">
- </p>
- <?php echo $nameError ?>
- <p>
- <label for="firstName">FirstName :*</label>
- <input type="text" id="firstName" name="firstName">
- </p>
- <?php echo $firstNameError ?>
- <p>
- <label for="email">E-mail :*</label>
- <input type="text" id="email" name="email">
- </p>
- <?php echo $emailError ?>
- <p>
- <label for="phone">Enter your phone number:*</label>
- <input type="phone" id="phone" name="phone"
- pattern="^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$">
- </p>
- <?php echo $phoneError ?>
- <p>
- <label for="subject">Choose an option:*</label>
- <select id="subject" name="subject">
- <option value=""> Please choose an option </option>
- <option value="option1">Option 1</option>
- <option value="option2">Option 2</option>
- </select>
- </p>
- <?php echo $subjectError ?>
- <p>
- <label for="message">Message :*</label>
- <textarea id="message" name="message"></textarea>
- </p>
- <?php echo $messageError ?>
- <div class="button">
- <button type="submit" name="isFormSubmitted">Send your message :
- </button>
- </div>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement