12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- // define variables and set to empty values
- $nameErr = $emailErr = $countryCodeErr = $telErr = $languageErr = $storyErr = "";
- $authorshipErr = $legalpermissionErr = "";
- $name = $email = $countryCode = $tel = $language = $story = "";
- $authorship = $legalpermission = "No";
- $wordsentered = 0;
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["name"])) {
- $nameErr = "Name/pseudonym is required";
- } else {
- $name = test_input($_POST["name"]);
- $nameErr = "";
- }
- if (empty($_POST["legalpermission"])){
- $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";
- }else{
- $legalpermission = test_input($_POST["legalpermission"]);
- $legalpermissionErr = "";
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- // check if e-mail address is well-formed
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $emailErr = "Invalid email format";
- } else {
- $emailErr = "";
- }
- }
- $countryCode = test_input($_POST["countryCode"]);
- if (empty($_POST["tel"])) {
- $telErr = "Telephone is required";
- } else {
- $tel = test_input($_POST["tel"]);
- $telErr = "";
- }
- if (empty($_POST["language"])) {
- $languageErr = "Please choose one of the available language options";
- } else {
- $language = test_input($_POST["language"]);
- $languageErr = "";
- }
- if (empty($_POST["title"])) {
- $titleErr = "Please add the title of your story";
- } else {
- $title = test_input($_POST["title"]);
- $titleErr = "";
- }
- if (empty($_POST["authorship"])) {
- $authorshipErr = "Please confirm that this is your work and that you allow others to use it provided that they attribute you as the author.";
- } else {
- $authorship = test_input($_POST["authorship"]);
- $authorshipErr = "";
- }
- if (empty($_POST["story"])) {
- $storyErr = "Please entry your story";
- } else {
- $story = test_input($_POST["story"]);
- $wordsentered = wordcount($story);
- if (($wordsentered < 750 ) || ($wordsentered > 1250 )) {
- if ($wordsentered < 750 ) {
- $storyErr = "Your story needs to be between 800 and 1200 words, and is currently less than 800 words.";
- } else {
- $storyErr = "Your story needs to be between 800 and 1200 words, and is currently more than 1200 words.";
- }
- } else {
- $storyErr = "";
- }
- }
- }
-
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- function wordcount($story) {
- $words = explode(' ', $story);
- $wordcount = count($words);
- return $wordcount;
- }
- ?>
|