Guest User

Untitled

a guest
Mar 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. if ($_POST) {
  4. $errors = array();
  5.  
  6. if (empty($_POST["userName"])) {
  7. $errors["userName"] = "Name is required";
  8. }
  9.  
  10. if(strlen($_POST['userName']) < 2 || strlen($_POST['userName']) > 32) {
  11. $errors['userName'] = "Name must be at least between 2 and 30 characters long";
  12. }
  13.  
  14. if (!preg_match('#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#',$_POST['userEmail'])) {
  15. $errors["userEmail"] = "Valid email adress is required";
  16. }
  17.  
  18. if (!preg_match("#^0[1-9]([-. ]?[0-9]{2}){4}$#", $_POST["userPhone"])) {
  19. $errors["userPhone"] = "Valid phone number is required";
  20. }
  21.  
  22. if (empty($_POST["userReason"])) {
  23. $errors["userReason"] = "Please select the reason of your message";
  24. }
  25.  
  26. if (empty($_POST["userMessage"])) {
  27. $errors["userMessage"] = "Please enter your message";
  28. }
  29.  
  30. if(strlen($_POST['userMessage']) < 2 || strlen($_POST['userMessage']) > 600) {
  31. $errors['userMessage'] = "Message must be at least between 2 and 600 characters long";
  32. }
  33.  
  34. if(count($errors) == 0) {
  35. unset($_POST);
  36. echo "<strong>Succes</strong>";
  37. }
  38. }
Add Comment
Please, Sign In to add comment