Skip to content
Snippets Groups Projects
Commit caa60ebf authored by Matthieu Guffroy's avatar Matthieu Guffroy
Browse files

Form: some cleanner msg

parent 23f635f8
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment