0
我嘗試使用CodeIgniter框架的項目使用引導驗證,但是當我插入當前值「ID」時,數據庫中已存在值時驗證不起作用。價值已經存在使用codeigniter bootstrapvalidation如果值已存在
ITS解決
這是我的控制器
public function check_user()
{
$id= $this->input->post('id');
$result= $this->mcrud->check_user_exist($id);
if($result)
{
echo "false";
}
else{
echo "true";
}
}
這是我的模型
public function check_user_exist($id)
{
$this->db->where('id',$id);
$query= $this->db->get('tbdetail');
if($query->num_rows()>0)
{
return $query->result();
}
else
{
return false;
}
}
,這我進行驗證
$(document).ready(function() {
$('#defaultForm').bootstrapValidator({
message: 'This value is not valid',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
id: {
row: '.col-md-3',
message: 'ID Tidak Valid',
validators: {
notEmpty: {
message: 'ID tidak boleh kosong'
},
remote: {
url: '<?php echo base_url(); ?>index.php/instrument/detailalat/check_user',
type:'POST',
message: 'ID sudah ada'
}
}
},
01 javascipt的
感謝@Niranjanñ拉朱,我嘗試,但它不是工作。控制器和模型有什麼問題? –
檢查控制檯,是傳遞給控制器的'id'?在控制器中回顯身份,看看你到達那裏。 –
也可以不用'return $ query-> result();'試一下,'return $ query-> num_rows();' –