Reputation: 100
Codeigniter check unique value while editing form.
When edit the form it checks for current row, and it give username already exist. so how to avoid it.and don't check for current record.
So how can i pass id to is_unique function in CI_Form_Validation class function and add condition?
See my below code:
$this->custom_validation->set_rules('username','Username',
'trim|required|max_length[30]|is_unique[adminuser.username]');
Upvotes: 0
Views: 589
Reputation: 332
Simply put a unique validation only if value of that field is changed ie.
$old_value='old value';
if ($posted_value!=$old_value) {
$this->custom_validation->set_rules('username','Username',
'trim|required|max_length[30]|is_unique[adminuser.username]');
} else {
$this->custom_validation->set_rules('username','Username',
'trim|required|max_length[30]);
}
Upvotes: 1