diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php index 0920a43..7dedebe 100644 --- a/application/controllers/Forms.php +++ b/application/controllers/Forms.php @@ -7,7 +7,7 @@ class Forms extends CI_Controller if(!$this->session->userdata('logged_in')){ redirect('users/login'); } - $data['title'] = 'Create Post'; + $data['title'] = 'Create Form'; $this->load->view('templates/header'); $this->load->view('forms/create', $data); $this->load->view('templates/footer'); @@ -21,6 +21,7 @@ class Forms extends CI_Controller // Example: Save the form data to the database $this->load->model('Form_model'); + $this->Form_model->save_form_data($decodedData); echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']); diff --git a/application/models/Form_model.php b/application/models/Form_model.php index 4d723aa..2ce65ac 100644 --- a/application/models/Form_model.php +++ b/application/models/Form_model.php @@ -1,10 +1,15 @@ +session->userdata('user_id'); + // Save the form data to the database $this->db->insert('forms', [ 'title' => $formData['title'], - 'description' => $formData['description'] + 'description' => $formData['description'], + 'user_id' => $user_id ]); $formId = $this->db->insert_id(); @@ -15,7 +20,6 @@ public function save_form_data($formData) { 'question_text' => $question['question'], 'question_type' => $question['type'] ]); - $questionId = $this->db->insert_id(); if ($question['type'] !== 'paragraph') { diff --git a/application/models/User_model.php b/application/models/User_model.php index 45ab929..f8adf8d 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -1,5 +1,5 @@ db->insert('Users', $data); + return $this->db->insert('users', $data); } // Log user in @@ -21,7 +21,7 @@ $this->db->where('username', $username); $this->db->where('password', $password); - $result = $this->db->get('Users'); + $result = $this->db->get('users'); if($result->num_rows() == 1){ return $result->row(0)->user_id; @@ -32,7 +32,7 @@ // Check username exists public function check_username_exists($username){ - $query = $this->db->get_where('Users', array('username' => $username)); + $query = $this->db->get_where('users', array('username' => $username)); if(empty($query->row_array())){ return true; } else { @@ -42,7 +42,7 @@ // Check email exists public function check_email_exists($email){ - $query = $this->db->get_where('Users', array('email' => $email)); + $query = $this->db->get_where('users', array('email' => $email)); if(empty($query->row_array())){ return true; } else { diff --git a/application/views/forms/create.php b/application/views/forms/create.php index 6229b97..e287059 100644 --- a/application/views/forms/create.php +++ b/application/views/forms/create.php @@ -10,7 +10,7 @@
-