submit.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. $name = $discord = $bedrock = $birthdate = $nameErr = "";
  3. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  4. $name = test_input($_POST["fname"]);
  5. if (!preg_match("/^[a-zA-Z-' ]*$/",$name)) {
  6. $nameErr = "Only letters and white space allowed.";
  7. }
  8. $discord = test_input($_POST["fdiscord"]);
  9. if (!preg_match("/.+#[0-9]{4}(?<!0000)/",$discord)) {
  10. $nameErr = "Discord name not valid";
  11. }
  12. $bedrock = test_input($_POST["fbedrock"]);
  13. if (!preg_match("/^[a-zA-Z-' ]*$/",$bedrock)) {
  14. $nameErr = "Only letters and white space allowed.";
  15. }
  16. $birthdate = test_input($_POST["fbirthdate"]);
  17. } else {
  18. $nameErr = "Request not valid.";
  19. }
  20. if ($nameErr == "") {
  21. echo "name " . $name . "<br>";
  22. echo "discord " . $discord . "<br>";
  23. echo "bedrock " . $bedrock . "<br>";
  24. echo "birthday " . $birthdate . "<br>";
  25. // send data somehow to db
  26. // end then redirect to the succes page
  27. header("Location: success.php");
  28. die();
  29. } else {
  30. header("Location: index.php?error=" . htmlspecialchars($nameErr));
  31. die();
  32. }
  33. function test_input($data) {
  34. $data = trim($data);
  35. $data = stripslashes($data);
  36. $data = htmlspecialchars($data);
  37. return $data;
  38. }
  39. ?>