Welcome Guest, Not a member yet? Register   Sign In
Why Isn't My Callback Working? [solved]
#1

[eluser]kirkaracha[/eluser]
I have a callback that isn't working.

From the rules array:
Code:
array(
                'field' => 'state_id',
                'label' => 'state',
                'rules' => 'trim|required|numeric'
            ),
            array(
                'field' => 'district_number',
                'label' => 'district number',
                'rules' => 'trim|required|numeric|callback__check_dupe_district'
            ),

The callback:

Code:
public function _check_dupe_district(){
        $query = $this->db->get_where('congress_districts',array('state_id' => $this->input->post('state_id'),'district_number' => $this->input->post('district_number')),0,0);
        if ($query->num_rows() > 0) {
            $this->set_message('_check_dupe_district','This district is already listed.');
            return FALSE;
        } else {
            return TRUE;
        }
    } // _check_dupe_district

I'm expecting it to display an error when I submit a form with a state_id and district_number that area already listed, but it doesn't. (I know they're already being used because I'm looking at the database.) What am I missing?
#2

[eluser]kierownik[/eluser]
I think it should be $this->form_validation->set_message and not $this->set_message
#3

[eluser]kirkaracha[/eluser]
Yeah, I fixed that and it still doesn't work.
#4

[eluser]kirkaracha[/eluser]
This works, but I'm not sure why the get_where way didn't.

Controller:
Code:
public function _check_dupe_district(){
    $state_id = $this->input->post('state_id');
    $district_number = $this->input->post('district_number');
    $dupes = $this->Congress_districts_model->check_duplicate_district($state_id,$district_number);
    if ($dupes->num_rows() > 0) {
        $this->form_validation->set_message('_check_dupe_district','This district is already listed.');
        return FALSE;
    } else {
        return TRUE;
    }
} // _check_dupe_district

Model:
Code:
public function check_duplicate_district($state_id,$district_number){
    $this->db->select('id');
    $this->db->where('state_id',$state_id);
    $this->db->where('district_number',$district_number);
    $this->db->from($this->table);
    return $this->db->get();
} // check_duplicate_district




Theme © iAndrew 2016 - Forum software by © MyBB