-
-
Save pulse00/1908730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// FormHandler class which checks user input and does some preformatting. It is called by the DataHandler class. | |
class FormHandler { | |
// Function to performat and check user inputs | |
public function preProcessor($stringField, $stringValue, $trim, $stripTags, $removeAllWhitespaces, $required, $email, $minLength, $maxLength, $minValue, $maxValue, $alphaOnly, $numericOnly, $alphaAndNumericOnly) { | |
// *** FORMATTING *** // | |
// Remove whitespaces from the beginning and the end | |
if($trim == 1) { $stringValue = trim($stringValue); } | |
// Strip HTML Tags | |
if($stripTags == 1) { $stringValue = strip_tags($stringValue); } | |
// Remove all whitespaces | |
if($removeAllWhitespaces == 1) { $stringValue = str_replace(" ", "", $stringValue); } | |
// *** INPUT CHECKS *** // | |
$error = false; | |
// Input is required | |
if($required == 1) { if(empty($stringValue)) { $error = true; $message = $this->getLangHandler()->translate("Eingabe erforderlich:")." ".$stringField; }} | |
if ($email == 1) { if(preg_match("/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})+$/i", $stringValue)) { $error = true; $message = translate("Falsches Format:")." ".$stringField; }} | |
// email, alpha, nummeric, both -> dann mit if, else if, else if oder ähnlich, damit sich das nicht in die quere kommt | |
// *** DATABASE CHECKS *** // | |
// unique : ggf. direkt im datahandler.php einbauen | |
// If an error occured, we send back an error message instead of the user input. the db array is check against any "Error:" in a loop in the DataHandler.php | |
if ($error == true) { $stringValue = "ErrorTag001: ".$message; } | |
return $stringValue; | |
} | |
// Function to create a new object of the LanguageHandler class. | |
private function getLangHandler() { | |
return new LangHandler(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment