From caa60ebf520caa795ed19ebe5bc5eaff913da7fc Mon Sep 17 00:00:00 2001 From: Matthieu Guffroy <mattgu74@gmail.com> Date: Wed, 18 Jun 2014 00:56:56 +0200 Subject: [PATCH] Form: some cleanner msg --- class/form.php | 23 ++++++++++++++++++----- class/objet.php | 8 ++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/class/form.php b/class/form.php index 4baf18a..a36e5f0 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 5f5646a..d97e3eb 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 -- GitLab