Welcome Guest, Not a member yet? Register   Sign In
Should form_validation only be done if post() is true?
#2

[eluser]CroNiX[/eluser]
No, you're not overthinking it and I do the same. There is no reason to load the validation library, set the rules or run the validation, unless there is data to validate.

I usually do something like...

Code:
$submitted = $this->input->post('submit'); //my submit button

if ($submitted)
{
  $this->load->library('form_validation');
  $this->form_validation->set_rules();

  if ($this->form_validation->run() !== FALSE)
  {
    //passed - maybe redirect, or add flashdata success message
  }
  else
  {
    //failed - add flashdata failure message
  }
}

//load the main view.
$this->load->view();
1) form comes up clean upon initial page load
2) if submitted, load and run validation
3) if errors, show errors and general error message
4) if passes, show success message...possibly redirect. Depends on case.


Messages In This Thread
Should form_validation only be done if post() is true? - by El Forum - 01-20-2014, 06:15 AM
Should form_validation only be done if post() is true? - by El Forum - 01-20-2014, 11:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB