function submit() { $data['title'] = 'Submit a Project'; $project = new Project(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Get the scalars. $project->from_array($_POST); // Convert properly to boolean if ($project->show_contact == 'yes') { $project->show_contact = TRUE; } else { $project->show_contact = FALSE; } // Handle the relations (tags) if ($project->save($this->_current_user())) { // validations run $this->_save_tags($project); $this->_submit_on_success(); } else { // invalid $data['error'] = $project->error->string; } } // Otherwise, render a form. $tags = new Tag(); foreach (array('field', 'type', 'location') as $category) { $tags->where('category', $category)->get(); $data[$category . '_tags'] = array(); foreach ($tags as $tag) { array_push($data[$category . '_tags'], $tag->name); } } $data['form'] = $project->render_form(array('title', 'start_date', 'end_date', 'field', 'type', 'location', 'text', 'show_contact')); $this->load->view('form_project', $data); }