From 29f2c12666b6e5e84bbd07533b7a4900be710fc8 Mon Sep 17 00:00:00 2001 From: Matthieu Guffroy <mattgu74@gmail.com> Date: Tue, 17 Jun 2014 23:51:12 +0200 Subject: [PATCH] Form: get data --- class/field.php | 10 ++++++++++ class/form.php | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/class/field.php b/class/field.php index 6a260eb..63c6efa 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 ffc4f52..bd85a4a 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 { -- GitLab