diff --git a/class/form.php b/class/form.php index 4baf18ade945e18723e202de8aee326bdcac287f..a36e5f0b8f85dd49db0888ff9ed0de75d883a297 100644 --- a/class/form.php +++ b/class/form.php @@ -3,6 +3,7 @@ class Form { protected $object; protected $action; + protected $error = null; public function __construct(&$obj) { $this->object =& $obj; @@ -26,11 +27,17 @@ class Form { // If all validators ok, commit if($success) { - if($this->action == "Modifier") { - $this->object->update(); - } else { - $this->object->insert(); + try { + if($this->action == "Modifier") { + $this->object->update(); + } else { + $this->object->insert(); + } + } catch (Exception $e) { + $this->error = $e->getMessage(); } + } else { + $this->error = "Tout les conditions de validations de formulaire ne sont pas passés." } } else { $post = false; @@ -50,7 +57,13 @@ class Form { } public function getAlerts() { - return '<p class="bg-danger">Code en cours d\'implémentation, l\'enregistrement n\'a pas été ajouté !</p>'; + if($this->error) { + return '<p class="bg-danger">'.$this->error.'</p>'; + } else { + if(isset($_POST["submitForm"])) { + return '<p class="bg-success">L\'opération a réussi avec succès.</p>'; + } + } } } \ No newline at end of file diff --git a/class/objet.php b/class/objet.php index 5f5646adf45906d83795bdd9cc40feb08b6d195b..d97e3ebe2081ca196d14dd3dbf769165942ff90c 100644 --- a/class/objet.php +++ b/class/objet.php @@ -80,17 +80,13 @@ class Objet $requete_prepare = $bdd->db->prepare($req); // on prépare notre requête if (!$requete_prepare) { - echo "\nPDO::errorInfo(): (STEP 1)\n"; - print_r($bdd->db->errorInfo()); - die(); + throw new Exception("PDO::errorInfo(): (STEP 1)\n". print_r($bdd->db->errorInfo(), true)); } $result = $requete_prepare->execute($params); if($result != 1) { - echo "RESULT : ".print_r($result,true)."\n"; - print_r($requete_prepare->errorInfo()); - die(); + throw new Exception("RESULT : ".print_r($result,true)."\n".print_r($requete_prepare->errorInfo(),true)); } } } \ No newline at end of file