Postingan lainnya
cara menggunakan form validation is_unique di CI ?
bagaimana cara memnggunakan form validation is_unique pada codeigniter gan ?
ini koding saya :
code view :
<h2>Form Register :</h2>
<?php echo validation_errors(); ?>
<?php echo form_open('register/check'); ?>
<input type="hidden" name="id">
<input type="text" name="nama" placeholder="Username :"><br>
<input type="email" name="email" placeholder="Email :"><br>
<input type="Password" name="password" placeholder="Password :"><br>
<input type="Password" name="pswd_again" placeholder="Re-enter Password :"><br>
<input type="submit" value="Register" name="btn_register">
<?php echo form_close() ?>
code controller :
public function check(){
$this->form_validation->set_rules('nama','Nama','required|min_length[5]|max_length[25]|is_unique[tb_user.nama]');
$this->form_validation->set_rules('email','Email','required|valid_email');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('pswd_again','Re-enter Password','required|matches[password]');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('formRegister');
$this->load->view('templates/footer');
}else{
echo "success";
}
}
semua validasi dari form di atas dapat berjalan normal,kecuali is_unique, dari pemahaman saya validasi is_unique ini digunakan untuk mengecek nilai di database sama atau tidak dan di dalam array is_unique terdapat nama_table.nama_atribut table,
masalahnya saat saya coba validasinya selalu bernilai false di bagian is_unique.
2 Jawaban:
coba cek disini gan
<a href='https://stackoverflow.com/questions/13692473/is-unique-for-codeigniter-form-validation '>https://stackoverflow.com/questions/13692473/is-unique-for-codeigniter-form-validation </a>
ane lihat problem nya sama kayak agan, semoga membantu
Jawaban Terpilih
udah bisa gan, ternyata atribut di database harus disetting unique juaga