[eluser]chuckl[/eluser]
I have a form that I need to validate but I can't figure out how to code the controller so that it works correctly the first time the page is displayed. Here is my code (simplified):
Code:
function index()
$data['somedata'] = $this->input->post('somedata');
$this->form_validation->set_rules('event', 'Event', 'trim|required|alpha_numeric');
... more set_rules ...
if($this->form_validation->run() == FALSE)
{
// Hasn't been run or there are validation errors
$this->load->view('eventview', $data);
}
else
{
// Process the event
}
The problem is that form_validation->run() is never FALSE because the $_POST array contains data from a previous form that is used by this second form. At the very beginning of the form_validation->run() function is the following code:
Code:
// Do we even have any data to process? Mm?
if (count($_POST) == 0)
{
return FALSE;
}
Since $_POST data exists the count is always greater than zero which results in the validation to be processed on initial page load.
Any suggestions as to how I might work around this?