Last active
August 29, 2015 14:10
-
-
Save seanmcn/bf2c62a18d00b7f44866 to your computer and use it in GitHub Desktop.
Using Codeigniter Form + Validation Libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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