How do I validate a form field in Codeigniter when using Get parameters?
For CodeIgniter 3, you can pass the GET array into the set_data
function. For example:$this->form_validation->set_data($this->input->get());
Codeigniter has changed since some of these posts. I think gX's answer is correct.
The instructions in the user manual, specifically section Validating an Array (other than $POST), worked great for me (as of today) and it's very simple.
Before your $this->form_validation->set_rules line, you specify the array to be validated:
$data = array(
'username' => 'johndoe',
'password' => 'mypassword',
'passconf' => 'mypassword');
$this->form_validation->set_data($data);
Just add:
$_POST['states'] = $this->input->get('states');
for validate states field in form validation just before
$this->form_validation->set_rules('states', 'states', 'required|trim');
This post on the Codeigniter Forum suggests that form validation does not work with Get Parameters and that is just the way Codeigniter is.