Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $title = "Contact Us";
- include 'header.php';
- if ( isset($_POST) && !empty($_POST) ) {
- // init error array
- $send = true;
- $errors = array();
- // check user name
- if ( !empty($_POST['username']) ) {
- $username = $_POST['username'];
- $pattern = "/^[a-z ,.'-]+$/i";
- if ( preg_match($pattern, $username) ) {
- $username = $_POST['username'];
- } else {
- $errors[] = "name";
- }
- } else {
- $errors[] = "name";
- }
- // check email
- if ( !empty($_POST['email']) ) {
- $userEmail = $_POST['email'];
- $pattern = "/^[\w&]([\w\-\.'&]*)@([\w\-\.]*)(\.[a-z]{2,6}(\.[a-z]{2}){0,2})$/i";
- if ( preg_match($pattern, $userEmail) ) {
- $userEmail = $_POST['email'];
- } else {
- $errors[] = 'email';
- }
- } else {
- $errors[] = "email";
- }
- // checking subject
- if ( !empty($_POST['subject']) ) {
- $subjectMessage = $_POST['username'] . " writes about: " . $_POST['subject'];
- } else {
- $errors[] = "subject";
- }
- // checking message
- if ( !empty($_POST['msg-body']) ) {
- $message = $_POST['msg-body'];
- } else {
- $errors[] = "msg";
- }
- }
- if ( empty($errors) && isset($send) ) {
- $from = "From: ".$username;
- $to = "email@domain.com";
- $mailMessage = "Message from contact form of xxx webpage. \n".
- "Sent by $username \n".
- "User writes following: \n".
- $message;
- $success = mail($to, $subjectMessage, $mailMessage, $from);
- }
- ?>
- <main class="contact">
- <p>Whether you want to enquire about a quote, find out more about a package or simply say hello – we’d love to hear from you. Fill out the form below and we’ll do our best to get back to you as soon as we can!</p>
- <?php if ( !empty($errors) ) { ?>
- <p class="notification">Specified fields are invalid. Please ensure that information is correct and try again.</p>
- <?php } ?>
- <?php if ( $success == true ) { ?>
- <p class="notification">Thank you for your message. We will contact you as soon as possible!</p>
- <?php } ?>
- <form action="contact.php" id="contact-form" method="POST" novalidate>
- <div class="form-part <?php if( isset($send) && in_array( "name", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="name">Name</label>
- <input type="text"
- id="name"
- name="username"
- required="required"
- data-pattern="plainText"
- value="<?php if ( isset($send) && $success === false ) echo $username?>">
- </div>
- <div class="form-part <?php if( isset($send) && in_array( "email", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="email">E-mail</label>
- <input type="email"
- id="email"
- name="email"
- required="required"
- data-pattern="email"
- value="<?php if ( isset($send) && $success === false ) echo $userEmail?>">
- </div>
- <div class="form-part <?php if( isset($send) && in_array( "subject", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="theme">Subject</label>
- <input type="text"
- id="theme"
- name="subject"
- required="required"
- data-pattern="plainText"
- value="<?php if ( isset($send) && $success === false ) echo $subject?>">
- </div>
- <div class="form-part msg-container <?php if( isset($send) && in_array( "msg", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="message">message</label>
- <textarea name="msg-body"
- id="message"
- placeholder="Drop us a message"
- required="required"
- data-pattern="plainText"><?php if ( isset($send) && $success === false ) echo $message?></textarea>
- </div>
- <input type="submit" class='button'>
- </form>
- </main>
- <?php
- include 'footer.php';
- ?>
- <script src='js/jquery.min.js'></script>
- <script src='js/misc.js'></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement