Skip to content

Instantly share code, notes, and snippets.

@tristar500
Created June 25, 2012 14:32
Show Gist options
  • Save tristar500/2989005 to your computer and use it in GitHub Desktop.
Save tristar500/2989005 to your computer and use it in GitHub Desktop.
CI Form Validation
//Check that the form was submitted
if ($this->input->post())
{
$this->load->library('form_validation');
//set rules...
$this->form_validation->set_rules('EID','EID','required');
//etc...
if ($this->form_validation->run() === FALSE)
{
//do stuff for form failure.
//Generally I don't do anything here as the form will load below and
//if there are errors it will display them
}
else
{
//do stuff for successful form submission
//save data, maybe set success message that the view will display (flashdata)
}
}
//do stuff regardless of whether form was submitted (show form)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment