PHP - Required Fields


SUBMITTED BY: Guest

DATE: Oct. 7, 2014, 12:28 p.m.

FORMAT: Text only

SIZE: 962 Bytes

HITS: 1357

  1. <?php
  2. // define variables and set to empty values
  3. $nameErr = $emailErr = $genderErr = $websiteErr = "";
  4. $name = $email = $gender = $comment = $website = "";
  5. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  6. if (empty($_POST["name"])) {
  7. $nameErr = "Name is required";
  8. } else {
  9. $name = test_input($_POST["name"]);
  10. }
  11. if (empty($_POST["email"])) {
  12. $emailErr = "Email is required";
  13. } else {
  14. $email = test_input($_POST["email"]);
  15. }
  16. if (empty($_POST["website"])) {
  17. $website = "";
  18. } else {
  19. $website = test_input($_POST["website"]);
  20. }
  21. if (empty($_POST["comment"])) {
  22. $comment = "";
  23. } else {
  24. $comment = test_input($_POST["comment"]);
  25. }
  26. if (empty($_POST["gender"])) {
  27. $genderErr = "Gender is required";
  28. } else {
  29. $gender = test_input($_POST["gender"]);
  30. }
  31. }
  32. ?>

comments powered by Disqus