From b0c708f170b7c371fd136aae691de8e4f5863026 Mon Sep 17 00:00:00 2001 From: josephkurian Date: Fri, 12 Jul 2024 15:23:54 +0530 Subject: [PATCH] its getting updated to the db --- application/models/Form_model.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/application/models/Form_model.php b/application/models/Form_model.php index e69de29..4d723aa 100644 --- a/application/models/Form_model.php +++ b/application/models/Form_model.php @@ -0,0 +1,31 @@ +class Form_model extends CI_Model { + +public function save_form_data($formData) { + // Save the form data to the database + $this->db->insert('forms', [ + 'title' => $formData['title'], + 'description' => $formData['description'] + ]); + + $formId = $this->db->insert_id(); + + foreach ($formData['questions'] as $question) { + $this->db->insert('questions', [ + 'form_id' => $formId, + 'question_text' => $question['question'], + 'question_type' => $question['type'] + ]); + + $questionId = $this->db->insert_id(); + + if ($question['type'] !== 'paragraph') { + foreach ($question['options'] as $option) { + $this->db->insert('options', [ + 'question_id' => $questionId, + 'option_text' => $option + ]); + } + } + } +} +}