Welcome Guest, Not a member yet? Register   Sign In
Form Validation with existing $_POST data
#1

[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?


Messages In This Thread
Form Validation with existing $_POST data - by El Forum - 06-25-2011, 10:00 AM
Form Validation with existing $_POST data - by El Forum - 06-25-2011, 04:36 PM
Form Validation with existing $_POST data - by El Forum - 06-26-2011, 10:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB