Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <section id="contact">
  2. <h1 class="section-header">Contact Us Directly</h1>
  3. <h4 class="text-center">Have any quesitons not answered in the <span><a href="questions.php">Questions Page</a></span>.</h4>
  4. <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
  5. <label for="fname">First Name</label>
  6. <input type="text" id="fname" name="firstname" value="<?php $firstname ?>" placeholder="Your name.." tabindex="1" autofocus>
  7. <span class="error"><?php $firstname_error ?></span>
  8. <label for="lname">Last Name</label>
  9. <input type="text" id="lname" name="lastname" value="<?php $lastname ?>" placeholder="Your last name.." tabindex="2">
  10. <span class="error"><?php $lastname_error ?></span>
  11. <label for="email">Email</label>
  12. <input type="text" id="email" name="email" value="<?php $email ?>" placeholder="Your email.." tabindex="3">
  13. <span class="error"><?php $email_error ?></span>
  14. <label for="message">Message</label>
  15. <textarea id="subject" name="message" value="<?php $message ?>" placeholder="Write something.." style="height:200px" tabindex="4"> </textarea>
  16. <span class="error"><?php $message_error ?></span>
  17. <input type="submit" value="Submit" tabindex="5">
  18. <span class="success"><?php $success ?></span>
  19. </form>
  20. </section>
  21.  
  22. <?php
  23.  
  24. $firstname_error = $lastname_error = $email_error = $message_error = "";
  25. $firstname = $lastname = $email = $message = $success = "";
  26.  
  27. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  28. if (empty($_POST["firstname"])) {
  29. $firstname_error = "First name is required";
  30. } else {
  31. $firstname = test_input($_POST["firstname"]);
  32. // check if name only contains letters and whitespace
  33. if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) {
  34. $firstname_error = "Only letters and white space allowed";
  35. }
  36. }
  37.  
  38. if (empty($_POST["lastname"])) {
  39. $lastname_error = "Last name is required";
  40. } else {
  41. $lastname = test_input($_POST["lastname"]);
  42. // check if name only contains letters and whitespace
  43. if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {
  44. $lastname_error = "Only letters and white space allowed";
  45. }
  46. }
  47.  
  48. if (empty($_POST["email"])) {
  49. $email_error = "Email is required";
  50. } else {
  51. $email = test_input($_POST["email"]);
  52. // check if e-mail address is well-formed
  53. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  54. $email_error = "Invalid email format";
  55. }
  56. }
  57.  
  58. if (empty($_POST["message"])) {
  59. $message = "";
  60. } else {
  61. $message = test_input($_POST["message"]);
  62. }
  63.  
  64.  
  65. if ($firstname_error == '' and $lastname_error == '' and $email_error == '' and $message_error == '' ){
  66. $message_body = '';
  67. unset($_POST['submit']);
  68. foreach ($_POST as $key => $value){
  69. $message_body .= "$key: $valuen";
  70. }
  71.  
  72. $EmailFrom = localhost;
  73. $EmailTo = "testrepairmail69@gmail.com";
  74. $Subject = "New Order From tabletscreenfixer.com";
  75. if (mail($EmailTo, $Subject, $message)){
  76. $success = "Message sent, thank you for contacting us!";
  77. $firstname = $lastname = $email = $message = '';
  78. }
  79. }
  80.  
  81. }
  82.  
  83.  
  84.  
  85. function test_input($data) {
  86. $data = trim($data);
  87. $data = stripslashes($data);
  88. $data = htmlspecialchars($data);
  89. return $data;
  90. }
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement