Created
December 30, 2019 09:57
-
-
Save moshiurse/81f61046d107ee6d1a4faa4fd252a22b to your computer and use it in GitHub Desktop.
Codeignitter form validation with Callback function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function check_unique() { | |
$conf_group = $this->input->post('conf_group'); | |
$label = $this->input->post('label'); | |
$code = strtolower(str_replace(' ', '_', $label)); | |
$this->db->select('code'); | |
$this->db->from('acc_meta_conf'); | |
$this->db->where('code', $code); | |
$this->db->where('conf_group', $conf_group); | |
$query = $this->db->get(); | |
$num = $query->num_rows(); | |
if ($num > 0) { | |
$this->form_validation->set_message('check_unique', 'Name is already taken'); | |
return FALSE; | |
} else { | |
return TRUE; | |
} | |
} | |
function savePublicationConfig($conf_id = NULL){ | |
$this->form_validation->set_rules('label', 'Name', 'callback_check_unique'); | |
if ($this->form_validation->run() == FALSE) { | |
echo json_encode(array('error' => validation_errors()), JSON_HEX_TAG); | |
}else{ | |
$this->PublicationConfig_mdl->savePublicationConfig($conf_id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment