From d1d602a941a7d07755176d5f69b57783d87d15a6 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 2 Aug 2023 19:10:35 +0200 Subject: [PATCH] Added error message when saving or editing a paper type with duplicate name --- application/controllers/Labels.php | 16 +++++++++++++--- application/views/labels/createpaper.php | 20 ++++++++++++++++---- application/views/labels/editpaper.php | 18 ++++++++++++++++-- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index 97ca48b5..15029d49 100644 --- a/application/controllers/Labels.php +++ b/application/controllers/Labels.php @@ -118,8 +118,12 @@ class Labels extends CI_Controller { else { $this->load->model('labels_model'); - $this->labels_model->addPaper(); - + try { + $this->labels_model->addPaper(); + } catch (\Throwable $th) { + $this->session->set_flashdata('error', 'Your paper could not be saved. Remember that it can\'t have the same name as existing paper types.'); + redirect('labels/createpaper'); + } redirect('labels'); } @@ -379,7 +383,13 @@ class Labels extends CI_Controller { public function updatePaper($id) { $this->load->model('labels_model'); - $this->labels_model->updatePaper($id); + try { + $this->labels_model->updatePaper($id); + } catch (\Throwable $th) { + $this->session->set_flashdata('error', 'Your paper could not be saved. Remember that it can\'t have the same name as existing paper types.'); + $cleanid = $this->security->xss_clean($id); + redirect('labels/editpaper/'.$cleanid); + } $this->session->set_flashdata('message', 'Paper was saved.'); redirect('labels'); } diff --git a/application/views/labels/createpaper.php b/application/views/labels/createpaper.php index ee721d98..6bc3f285 100644 --- a/application/views/labels/createpaper.php +++ b/application/views/labels/createpaper.php @@ -3,8 +3,22 @@
session->flashdata('message')) { ?> -
-

session->flashdata('message'); ?>

+ + + + session->flashdata('error')) { ?> + + + + + session->flashdata('warning')) { ?> + + @@ -33,8 +47,6 @@
- -
diff --git a/application/views/labels/editpaper.php b/application/views/labels/editpaper.php index cddfb59a..f7de1553 100644 --- a/application/views/labels/editpaper.php +++ b/application/views/labels/editpaper.php @@ -3,8 +3,22 @@
session->flashdata('message')) { ?> -
-

session->flashdata('message'); ?>

+ + + + session->flashdata('error')) { ?> + + + + + session->flashdata('warning')) { ?> + +