diff --git a/class/field.php b/class/field.php index 6a260ebef6bd0ea83e27fe55ac4a5d1a2f2ee02b..63c6efa12dbf1e6d68d163df594e0844bec95344 100644 --- a/class/field.php +++ b/class/field.php @@ -9,10 +9,20 @@ class Field { } public function html() { + // Todo, if isset($_POST[$this->name]) && !$this->validate() => Show a error msg explanation for this line. return '<div class="form-group"> <label for="form'.$this->name.'">'.ucfirst($this->name).'</label> <input type="text" class="form-control" name="'.$this->name.'" value="'.$this->value.'" > </div>'; } + /* + Load the data from $_POST + and return false, if data is not valid ! + */ + public function validate() { + $this->value = $_POST[$this->name]; + return true; + } + } \ No newline at end of file diff --git a/class/form.php b/class/form.php index ffc4f5238cc06996e4681bacac50aa1a241ded94..bd85a4a5c5426963d3b544889cc18de8c5184c30 100644 --- a/class/form.php +++ b/class/form.php @@ -19,6 +19,10 @@ class Form { if(isset($_POST["submitForm"])) { $post = true; // Apply validators + $success = true; + foreach($this->fields as $field) { + $success = $success && $field->validate(); + } // If all validators ok, commit } else {