需要添加表单验证codeigniter

I want to add form validation if the ip_address duplicated just stay on current page or show me any kind of message.

this is the model code

  public function add_vote($option_id)
    {
        $this->db->insert($this->votes_table, array(
            'option_id' => $option_id,
            'ip_address' => $this->input->ip_address(),
            'timestamp' => time()
        ));

        return ($this->db->affected_rows() == 1) ? TRUE : FALSE;
    }

this is the controler

public function vote($poll_id, $option_id)
    {
        if ( ! $this->poll_lib->vote($poll_id, $option_id))
        {
            $data['base_styles'] = 'public_html/res/css/base.css';
            $data['title'] = 'Sorry an error occured';
            $data['error_message'] = $this->poll_lib->get_errors();
            $this->load->view('header');
            $this->load->view('www/posts/postclose', $data);
        }
        else
        {
            redirect('posts', 'refresh');
        }
    }

hear if i add new vote it's shows me database error as the column is duplicate so i don't want to show that, if it redirect me to any other page will be great if stay on current page still ok or any pop up message.

Do a check before inserting into database.

public function add_vote($option_id)
    {   
        $query = $this->db->get_where($this->votes_table, array('ip_address' => $this->input->ip_address()));

        if($query->num_rows() < 1)

        {    $this->db->insert($this->votes_table, array(
                'option_id' => $option_id,
                'ip_address' => $this->input->ip_address(),
                'timestamp' => time()
             ));

             return "Successfully Inserted";
        }else{
               return "Duplicate";
              } 
    }

In your controller handle the response and display accordingly