diff --git a/application/controllers/New_form_controller.php b/application/controllers/New_form_controller.php new file mode 100644 index 0000000..fea61d5 --- /dev/null +++ b/application/controllers/New_form_controller.php @@ -0,0 +1,24 @@ +input->post('formData'); + + + $formId = $this->session->userdata('form_id'); + if ($formId) { + // Save questions and options associated with the form_id + $this->load->model('new_form_model'); + $this->new_form_model->save_form_data($formId, $formData); + + echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to submit form data']); + } + } + +} +?> \ No newline at end of file diff --git a/application/controllers/Your_controller.php b/application/controllers/Your_controller.php deleted file mode 100644 index 4700dd6..0000000 --- a/application/controllers/Your_controller.php +++ /dev/null @@ -1,20 +0,0 @@ -session->userdata('user_id'); - - // Query to fetch form_id from database based on user_id - $form_id = $this->your_model->getFormIdByUserId($user_id); // Replace with your actual model method - - // Return form_id as JSON response - $this->output - ->set_content_type('application/json') - ->set_output(json_encode(array('form_id' => $form_id))); -} -} diff --git a/application/models/Create_model.php b/application/models/Create_model.php index 9b8723f..1d4fd94 100644 --- a/application/models/Create_model.php +++ b/application/models/Create_model.php @@ -1,11 +1,8 @@ session->userdata('user_id'); @@ -18,7 +15,13 @@ class Create_model extends CI_Model // Insert data into forms table $this->db->insert('forms', $data); - } -} + // Store form_id in session + $formId = $this->db->insert_id(); + $this->session->set_userdata('form_id', $formId); + + + } + +} ?> diff --git a/application/models/New_form_model.php b/application/models/New_form_model.php new file mode 100644 index 0000000..0b53b28 --- /dev/null +++ b/application/models/New_form_model.php @@ -0,0 +1,34 @@ + $formId, + 'text' => $question['text'], + 'type' => $question['type'], + 'required' => ($question['required'] == 'true') ? 0 : 1 + ]; + + $this->db->insert('questions', $questionData); + $questionId = $this->db->insert_id(); // Get the inserted question_id + + foreach ($question['options'] as $option) { + $optionData = [ 'question_id' => $questionId, + 'option_text' => $option]; + + // Insert option into options table + $this->db->insert('options', $optionData); + } + } + + return true; // Return true indicating success + } + + + +} +?> diff --git a/application/models/Your_model.php b/application/models/Your_model.php deleted file mode 100644 index 39bf107..0000000 --- a/application/models/Your_model.php +++ /dev/null @@ -1,19 +0,0 @@ - -db->select('form_id'); - $this->db->where('user_id', $user_id); - $query = $this->db->get('forms'); // Replace 'your_forms_table' with your actual table name - - if ($query->num_rows() > 0) { - $row = $query->row(); - return $row->form_id; - } else { - return null; // Handle case when form_id is not found - } -} -} \ No newline at end of file diff --git a/application/views/templates/forms_ui.php b/application/views/templates/forms_ui.php index a696c7c..deb01c2 100644 --- a/application/views/templates/forms_ui.php +++ b/application/views/templates/forms_ui.php @@ -35,6 +35,9 @@ +