From 7cd47655472040f79a1ce10492a72a2a8b71f9b5 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Wed, 22 Nov 2023 16:46:34 +0100 Subject: [PATCH] =?UTF-8?q?verifier=20les=20donn=C3=A9es=20avant=20d'ajout?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/src/controller/AdminController.php | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/project/src/controller/AdminController.php b/project/src/controller/AdminController.php index 0f1e7c1..4bc5f7f 100755 --- a/project/src/controller/AdminController.php +++ b/project/src/controller/AdminController.php @@ -40,6 +40,13 @@ class AdminController { if(isset($_GET["id"])){ $id=intval($_GET["id"]); } + try{ + $this->verifierDonnees(); + } catch (Exception $ex){ + $dVueErreur[] = 'Erreur : '.$ex; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + return; + } $sci = new Scientifique( $id, $_POST["name"], @@ -92,6 +99,39 @@ class AdminController { } + private function verifierDonnees(){ + $sexe = new MdlSexe(); + $theme = new MdlThematique(); + $diff = new MdlDifficulte(); + $selectTheme=$theme->getFromId(intval($_POST["theme"])); + $selectDiff=$diff->getFromId(intval($_POST["difficulte"])); + $selectSexe=$sexe->getFromId(intval($_POST["sexe"])); + //todo : verifier les données, mettre dans une fonction et try catch + if(strlen($_POST["name"]) < 2){ + throw new Exception("nom trop court"); + } + if(strlen($_POST["prenom"]) < 2){ + throw new Exception("prénom trop court"); + } + if(empty($_POST["url"])){ + throw new Exception("pas de photo"); + } + if(strlen($_POST["name"]) < 2){ + throw new Exception("nom trop court"); + } + if(strlen($_POST["description"]) < 20){ + throw new Exception("description trop courte "); + } + if($selectTheme==null){ + throw new Exception("thematique inconnue"); + } + if($selectSexe==null){ + throw new Exception("sexe inconnu"); + } + if($selectDiff==null){ + throw new Exception("difficulté inconnue"); + } + } } ?> \ No newline at end of file