Added error message when saving or editing a paper type with duplicate name

This commit is contained in:
Andreas
2023-08-02 19:10:35 +02:00
parent e0977ea3d7
commit d1d602a941
3 changed files with 45 additions and 9 deletions

View File

@@ -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');
}

View File

@@ -3,8 +3,22 @@
<br>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
<div class="alert alert-success" role="alert">
<?php echo $this->session->flashdata('message'); ?>
</div>
<?php } ?>
<?php if($this->session->flashdata('error')) { ?>
<!-- Display Message -->
<div class="alert alert-danger" role="alert">
<?php echo $this->session->flashdata('error'); ?>
</div>
<?php } ?>
<?php if($this->session->flashdata('warning')) { ?>
<!-- Display Message -->
<div class="alert alert-warning" role="alert">
<?php echo $this->session->flashdata('warning'); ?>
</div>
<?php } ?>
@@ -33,8 +47,6 @@
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label" for="width">Width of paper</label>
<div class="col-sm-4">

View File

@@ -3,8 +3,22 @@
<br>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
<div class="alert alert-success" role="alert">
<?php echo $this->session->flashdata('message'); ?>
</div>
<?php } ?>
<?php if($this->session->flashdata('error')) { ?>
<!-- Display Message -->
<div class="alert alert-danger" role="alert">
<?php echo $this->session->flashdata('error'); ?>
</div>
<?php } ?>
<?php if($this->session->flashdata('warning')) { ?>
<!-- Display Message -->
<div class="alert alert-warning" role="alert">
<?php echo $this->session->flashdata('warning'); ?>
</div>
<?php } ?>