submittranslationsetup1.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // define variables and set to empty values
  3. $nameErr = $emailErr = $countryCodeErr = $telErr = $languagefromErr = $languagetoErr = "";
  4. $storyErr = $authorshipErr = $legalpermissionErr = "";
  5. $name = $email = $countryCode = $tel = $languagefrom = $languageto = $story = "";
  6. $authorship = $legalpermission = "No";
  7. $originalid = "";
  8. $originalidErr = "";
  9. $wordsentered = 0;
  10. $originaltitle = "";
  11. $originallanguagename = "";
  12. $translatedlanguagename = "";
  13. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  14. if (empty($_POST["name"])) {
  15. $nameErr = "Name/pseudonym is required";
  16. } else {
  17. $name = test_input($_POST["name"]);
  18. $nameErr = "";
  19. }
  20. if (empty($_POST["legalpermission"])){
  21. $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";
  22. }else{
  23. $legalpermission = test_input($_POST["legalpermission"]);
  24. $legalpermissionErr = "";
  25. }
  26. if (empty($_POST["email"])) {
  27. $emailErr = "Email is required";
  28. } else {
  29. $email = test_input($_POST["email"]);
  30. // check if e-mail address is well-formed
  31. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  32. $emailErr = "Invalid email format";
  33. } else {
  34. $emailErr = "";
  35. }
  36. }
  37. $countryCode = test_input($_POST["countryCode"]);
  38. if (empty($_POST["tel"])) {
  39. $telErr = "Telephone is required";
  40. } else {
  41. $tel = test_input($_POST["tel"]);
  42. $telErr = "";
  43. }
  44. if (empty($_POST["languagefrom"])) {
  45. $languagefromErr = "Please choose one of the available language options to translate from";
  46. } else {
  47. $languagefrom = test_input($_POST["languagefrom"]);
  48. $languagefromErr = "";
  49. }
  50. if (empty($_POST["languageto"])) {
  51. $languagetoErr = "Please choose one of the available language options to translate to";
  52. } else {
  53. $languageto = test_input($_POST["languageto"]);
  54. $languagetoErr = "";
  55. }
  56. if (empty($_POST["title"])) {
  57. $titleErr = "Please add the translated story title";
  58. } else {
  59. $title = test_input($_POST["title"]);
  60. $titleErr = "";
  61. }
  62. if (empty($_POST["originalid"])) {
  63. $originalidErr = "Please ensure you have selected a story to translate";
  64. } else {
  65. $originalid = test_input($_POST["originalid"]);
  66. $originalidErr = "";
  67. }
  68. if (empty($_POST["translator"])) {
  69. $translatorErr = "Please confirm that this is your translation and that you allow others to use it provided that they attribute you as the translator.";
  70. } else {
  71. $translator = test_input($_POST["translator"]);
  72. $translatorErr = "";
  73. }
  74. if (empty($_POST["story"])) {
  75. $storyErr = "Please entry your translated story";
  76. } else {
  77. $story = test_input($_POST["story"]);
  78. $wordsentered = wordcount($story);
  79. if (($wordsentered < 1400 ) || ($wordsentered > 3100 )) {
  80. $storyErr = "Your translated story needs to be between 1500 and 3000 words, and is currently ". $wordsentered . " words.";
  81. } else {
  82. $storyErr = "";
  83. }
  84. }
  85. }
  86. function test_input($data) {
  87. $data = trim($data);
  88. $data = stripslashes($data);
  89. $data = htmlspecialchars($data);
  90. return $data;
  91. }
  92. function wordcount($story) {
  93. $words = explode(' ', $story);
  94. $wordcount = count($words);
  95. return $wordcount;
  96. }
  97. ?>