Skip to content

Instantly share code, notes, and snippets.

@seanmcn
Last active August 29, 2015 14:10
Show Gist options
  • Save seanmcn/bf2c62a18d00b7f44866 to your computer and use it in GitHub Desktop.
Save seanmcn/bf2c62a18d00b7f44866 to your computer and use it in GitHub Desktop.
Using Codeigniter Form + Validation Libraries
/*
* Controller for Projects
*/
public function addProject() {
$this->load->helper('form');
$this->load->library('form_validation');
$config = array(
array(
'field' => 'client',
'label' => 'Client Name',
'rules' => 'required'
),
array(
'field' => 'project_name',
'label' => 'Project Name',
'rules' => 'required'
),
array(
'field' => 'price',
'label' => 'Price',
'rules' => 'required|numeric'
)
);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == TRUE)
{
$this->projects_model->addProject(
$this->input->post('client'),
$this->input->post('project_name'),
$this->input->post('price'),
$this->input->post('deadline'),
$this->input->post('notes')
);
$this->session->set_flashdata('success_message', 'Project Successfully Added!');
redirect("/projects/");
}
else{
$this->load->view('projects/add', isset($data) ? $data : NULL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment