$formId, 'text' => $question['text'], 'type' => $question['type'], 'required' => ($question['required'] == 'true') ? 1 : 0 ]; $this->db->insert('questions', $questionData); $questionId = $this->db->insert_id(); // Get the inserted question_id // Handle options for multiple-choice, checkboxes, and dropdown questions if ($question['type'] === 'multiple-choice' || $question['type'] === 'checkboxes' || $question['type'] === 'dropdown') { 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 } } ?>