submitsetup.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // define variables and set to empty values
  3. $nameErr = $emailErr = $countryCodeErr = $telErr = $languageErr = $storyErr = "";
  4. $authorshipErr = $legalpermissionErr = "";
  5. $name = $email = $countryCode = $tel = $language = $story = "";
  6. $authorship = $legalpermission = "No";
  7. $wordsentered = 0;
  8. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  9. if (empty($_POST["name"])) {
  10. $nameErr = "Name/pseudonym is required";
  11. } else {
  12. $name = test_input($_POST["name"]);
  13. $nameErr = "";
  14. }
  15. if (empty($_POST["legalpermission"])){
  16. $legalpermissionErr = "Please indicate if you are an adult in your region of residence or if not, have permission from your legal guardian/parent(s) to make a submission";
  17. }else{
  18. $legalpermission = test_input($_POST["legalpermission"]);
  19. $legalpermissionErr = "";
  20. }
  21. if (empty($_POST["email"])) {
  22. $emailErr = "Email is required";
  23. } else {
  24. $email = test_input($_POST["email"]);
  25. // check if e-mail address is well-formed
  26. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  27. $emailErr = "Invalid email format";
  28. } else {
  29. $emailErr = "";
  30. }
  31. }
  32. $countryCode = test_input($_POST["countryCode"]);
  33. if (empty($_POST["tel"])) {
  34. $telErr = "Telephone is required";
  35. } else {
  36. $tel = test_input($_POST["tel"]);
  37. $telErr = "";
  38. }
  39. if (empty($_POST["language"])) {
  40. $languageErr = "Please choose one of the available language options";
  41. } else {
  42. $language = test_input($_POST["language"]);
  43. $languageErr = "";
  44. }
  45. if (empty($_POST["title"])) {
  46. $titleErr = "Please add the title of your story";
  47. } else {
  48. $title = test_input($_POST["title"]);
  49. $titleErr = "";
  50. }
  51. if (empty($_POST["authorship"])) {
  52. $authorshipErr = "Please confirm that this is your work and that you allow others to use it provided that they attribute you as the author.";
  53. } else {
  54. $authorship = test_input($_POST["authorship"]);
  55. $authorshipErr = "";
  56. }
  57. if (empty($_POST["story"])) {
  58. $storyErr = "Please entry your story";
  59. } else {
  60. $story = test_input($_POST["story"]);
  61. $wordsentered = wordcount($story);
  62. if (($wordsentered < 2000 ) || ($wordsentered > 2500 )) {
  63. if ($wordsentered < 2000 ) {
  64. $storyErr = "Your story needs to be between 2000 and 2500 words, and is currently less than 2000 words.";
  65. } else {
  66. $storyErr = "Your story needs to be between 2000 and 2500 words, and is currently more than 2500 words.";
  67. }
  68. } else {
  69. $storyErr = "";
  70. }
  71. }
  72. }
  73. function test_input($data) {
  74. $data = trim($data);
  75. $data = stripslashes($data);
  76. $data = htmlspecialchars($data);
  77. return $data;
  78. }
  79. function wordcount($story) {
  80. $words = explode(' ', $story);
  81. $wordcount = count($words);
  82. return $wordcount;
  83. }
  84. ?>