Hallo,
Das brauchst du doch gar nicht. Du rufst die Funktion auf und bekommst ein TRUE oder FALSE zurück.
Wenn FALSE, weisst du $error den passenden Text zu.
$success = pruefeZeit($zeit);
if($success === FALSE) {
$error = "Passende Fehlermeldung";
}
hab ich dich so richtig verstanden?
~~~php
if(isset($_POST['abschicken'])){
function check_time($hour, $minute)
{
if (in_array($hour, range(0, 23))
and in_array($minute, range(0, 59))) return TRUE;
return FALSE;
}
function handleTimeInput($input) {
global $errors;
$parts = explode(':',$input);
$gueltig = check_time($parts[0], $parts[1]);
if ($gueltig === FALSE) {
return NULL;
} else {
$parts[0] = str_pad($parts[0], 2, "0", STR_PAD_LEFT);
$parts[1] = str_pad($parts[1], 2, "0", STR_PAD_LEFT);
$input = $parts[0] .":". $parts[1];
return $input;
}
}
und die Prüfung mache ich dann so
if (strlen($_POST['montagvon']) > 0) {
$success = handleTimeInput($_POST['montagvon']);
if($success === NULL) {
$errors[] = "Montag von ist falsch";
}}
if (strlen($_POST['montagbis']) > 0) {
$success = handleTimeInput($_POST['montagbis']);
if($success === NULL) {
$errors[] = "Montag bis ist falsch";
}}
oder könnte man das noch weiter in die Funktion mit einbauen?