function check_form() { $this->DBG->enter_method(); #while (list($key, $val)=each($this->fieldlist)) { foreach ($this->fieldlist as $val) { $formval = init($val['name'], "r", false); // wert holen aus "request" $this->DBG->watch_var("!!Found " . $val['type'], $formval); if (array_key_exists('optional', $val) && $val['optional'] == true) { if (!($formval != "" || array_key_exists('minmax', $val))) { $this->DBG->send_message("-optional field ignored"); continue; } $this->DBG->send_message("-optional field processed!"); } switch ($val['type']) { case "file": $this->DBG->watch_var("-File uploaded/" . $formval . " ex?", file_exists("uploaded/" . $formval)); if (strlen($formval) > 1) { if (!file_exists("uploaded/" . $formval)) { $this->DBG->send_message("-file upload error [file1]"); $this->fielderrors[$val['name']] = "Fehler beim Hochladen?"; } else { $this->DBG->send_message("-file already uploaded [file2]"); array_push($this->results, array($val['name'] => $formval)); } continue; } else { $reti = FORM::upload_file($val['name'], "uploaded/"); if (substr($reti, 0, 5) == "ERROR") { // error occured with uploaded file $this->DBG->send_message("-error during file upload [file3]"); $this->fielderrors[$val['name']] = substr($reti, 6); } else { //echo $reti; // is filename $this->DBG->send_message("-file successfully uploaded [file4]"); array_push($this->results, array($val['name'] => $reti)); } } break; case "link": if (eregi("^http\\:", $formval)) { $this->fielderrors[$val['name']] = "Links bitte ohne Protokoll (http://) angeben."; } else { array_push($this->results, array($val['name'] => trim($formval))); } break; case "date": $this->DBG->watch_var("-input", $formval); $r = $this->check_date($formval); $this->DBG->watch_var("-output", $r); if (!eregi("^[0-9]", $r)) { $this->DBG->send_message("-invalid date!"); $this->fielderrors[$val['name']] = $r; } else { array_push($this->results, array($val['name'] => $r)); $_REQUEST[$val['name']] = $r; } break; case "site_select": $formval = init(substr($val['name'], 0, -2), "r"); // wert holen aus "request" $this->DBG->watch_var("-SiteSelect:" . $val['name'], $formval); // trivial if (is_array($formval)) { array_push($this->results, array($val['name'] => $formval)); break; } $this->fielderrors[$val['name']] = "Bitte wählen Sie mindestens einen Bereich aus!"; break; case "source_select": // trivial $this->DBG->watch_var("-F:" . $val['name'], $formval); if ($formval > 0) { array_push($this->results, array($val['name'] => $formval)); break; } $this->fielderrors[$val['name']] = "Bitte wählen Sie eine Quelle aus oder erstellen eine neue!"; break; default: $this->DBG->watch_var("-Default, Type is", $val['type']); case "text": // trivial $this->DBG->watch_var("-Text-Field", $val); $this->DBG->watch_var("-OR-Field", $val['_or']); /* Bedingungsliste */ // wert? (bool) ($wert = strlen(trim($formval)) > 0); $this->DBG->watch_var("wert", $wert); // abhängigkeit (bool) ($or = array_key_exists('_or', $val)); $this->DBG->watch_var("or", $or); // abhängiges feld hat wert (hat keinen fehler) (bool) ($or_wert = $or ? !array_key_exists($val['_or'], $this->fielderrors) : false); $this->DBG->watch_var("or_wert", $or_wert); // besteht eine min/max bedingung? (bool) ($minmax = array_key_exists('minmax', $val) ? true : false); // ist feld optional? (dann darf es leer sein, oder muss die min/max bedingung erfüllen) (bool) ($optional = array_key_exists('optional', $val) && $val['optional'] == true ? true : false); // wert vorhanden, schreiben! $error = false; if ($wert && $minmax) { $error = $this->_check_minmax_length($val, $formval); } // XOR Bedingung if ($wert and $or) { if ($or_wert) { // zuviel $or_field_name = $this->fieldlist[$val['_or']]['label']; //$this->fielderrors[$val['name']] $error = "Dieses Feld wird ignoriert werden, da bereits '" . $or_field_name . "' ausgefüllt ist."; } else { // genau richtig, fehler löschen $error = $this->_check_minmax_length($val, $formval); if (!$error) { $this->fielderrors[$val['_or']] = false; } // fehler löschen } } if (!$wert && $or && !$or_wert) { $or_field_name = $this->get_field_property($val['_or'], 'label'); $error = "Dieses Feld oder '" . $or_field_name . "' muss ausgefüllt werden. "; } // kein Wert, keine Alternative if (!$wert && !$or && !$optional) { $error = "Dieses Feld muss ausgefüllt werden. "; } // kein Wert aber Längendefinition vorhanden if (!$wert && $error && $minmax) { $error .= " (min. " . $val['minmax']['min'] . " und max. " . $val['minmax']['max'] . " Zeichen)"; } // central error or value setter $this->DBG->watch_var("Text-Errors", $error); if ($error) { $this->fielderrors[$val['name']] = $error; } else { array_push($this->results, array($val['name'] => $formval)); } break; // final break; } // switch } // while $this->DBG->send_message("!!END Fields;"); $thereareerrors = !empty($this->fielderrors); $this->DBG->watch_var("!Any errors", $thereareerrors); $realerrors = false; while (list($key, $val) = each($this->fielderrors)) { if ($val != false) { $realerrors == true; } } $this->DBG->watch_var("!Only real!errors", $realerrors); if ($thereareerrors && $realerrors) { // Fehlerfall $this->DBG->watch_var("!Errors (should be some)", $this->fielderrors); $this->DBG->send_message("Errors, showing form..."); $this->show(); // if errors $reti = false; } else { // kein Fehler oder kein echter //!(count($this->fielderrors)==1 && $this->fielderrors['source']==FALSE) ) { $reti = $this->results; $this->DBG->watch_var("!Result", $reti); $this->DBG->watch_var("!Errors (should be null)", $this->fielderrors); } $this->DBG->leave_method($reti); return $reti; }
function check_form() { $this->DBG->enter_method(); while (list($key, $val) = each($this->fieldlist)) { switch ($val['type']) { case "file": $this->DBG->watch_var("a file", $val); $reti = FORM::upload_file($val['name'], "uploaded/"); if (substr($reti, 0, 5) == "ERROR") { // error occured with uploaded file // msg is substr($reti,6) echo "<br>An error occured with uploaded file: " . substr($reti, 6) . "<p><a href='javascript:history.back();'>zurück und korrigieren</a></p>"; } else { echo $reti; } break; case "": break; } // switch } // while echo $reti; $this->DBG->leave_method($reti); }