Postingan lainnya
Notifikasi untuk validasi input/update data di codeigniter
Selamat sore kakak kakak sekalian, saya mau bertanya soal notifikasi untuk validasi data. bagaimana caranya saat saya input/update data nantinya akan ada notifikasi apabila data sudah digunakan. adapun script saya saat ini :
Controller :
//Tambah data Dosen
public function dosen_tambah()
{
$admins = $this->dosen_model;
$validation = $this->form_validation;
$validation->set_rules($admins->rules());
if ($validation->run() == TRUE)
{
$admins->simpan();
$this->session->set_flashdata('success', 'Data Berhasil disimpan');
if (!$admins)
{
header('Location: dosen_data');
}
else
{
echo "Data Gagal Diupdate";
echo "<br>";
echo "<a href='".base_url('admin/dosen_data/')."'>Kembali</a>";
$this->session->set_flashdata('danger', 'Data Gagal disimpan');
}
}
$this->load->view("admin/data_dosen/dosen_tambah");
}
Model :
//simpan data tabel dari database
public function simpan()
{
$post = $this->input->post();
$this->nidn = $post["nidn"];
$this->nama_dosen = $post["nama_dosen"];
$this->password = sha1($post["password"]);
$this->telepon = $post["telepon"];
$this->email = $post["email"];
$this->alamat = $post["alamat"];
$this->db->insert($this->_table, $this);
if($this->db->affected_rows() > 0){
return true;
}
else
{
return false;
}
}
//ambil id data dari database
public function ambil($id)
{
return $this->db->get_where($this->_table, ["nidn" => $id])->row();
}
View :
<form role="form" action="<?php echo base_url().'admin/dosen_tambah'; ?>" method="POST">
<div class="box-body">
<div class="form-group">
<label>NIDN</label>
<input type="number" name="nidn" id="nidn" class="form-control" required>
<?php echo form_error('nidn'); ?>
</div>
<div class="form-group">
<label>Nama Lengkap</label>
<input type="text" name="nama_dosen" id="nama_dosen" class="form-control" required>
<?php echo form_error('nama_dosen'); ?>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" id="password" class="form-control" required>
<?php echo form_error('password'); ?>
</div>
<div class="form-group">
<label>Telepon</label>
<input type="number" name="telepon" id="telepon" class="form-control" required>
<?php echo form_error('number'); ?>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" id="email" class="form-control" required>
<?php echo form_error('email'); ?>
</div>
<div class="form-group">
<label>Alamat</label>
<textarea type="text" name="alamat" id="alamat" class="form-control" required></textarea>
<?php echo form_error('alamat'); ?>
</div>
</div>
<div class="box-footer">
<button type="submit" value="simpan" class="btn btn-primary">Submit</button>
</div>
</form>
Notifikasi saat ini :
0
2 Jawaban:
coba kasih pengecekan nidn dulu
<pre>
public function simpan()
{
$post = $this->input->post();
$this->nidn = $post["nidn"];
$this->nama_dosen = $post["nama_dosen"];
$this->password = sha1($post["password"]);
$this->telepon = $post["telepon"];
$this->email = $post["email"];
$this->alamat = $post["alamat"];
if ($this-&gt;ambil($post["nidn"])) { // cek nidn ada atau engga
return false;
}else {
$this-&gt;db-&gt;insert($this-&gt;_table, $this);
if($this-&gt;db-&gt;affected_rows() &gt; 0){
return true;
}
else
{
return false;
}
}
}
</pre>
1