2024-07-15 12:45:25 +00:00
|
|
|
<?php
|
|
|
|
class New_form_model extends CI_Model {
|
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
public function save_form_data($formId, $formData) {
|
2024-07-15 12:45:25 +00:00
|
|
|
if (!$formId) {
|
|
|
|
return false; // Handle error if formId is not valid
|
|
|
|
}
|
2024-07-19 10:46:18 +00:00
|
|
|
|
2024-07-16 12:29:59 +00:00
|
|
|
$questions_array = $formData['questions'];
|
2024-07-19 10:46:18 +00:00
|
|
|
|
2024-07-16 12:29:59 +00:00
|
|
|
foreach ($questions_array as $question) {
|
2024-07-15 12:45:25 +00:00
|
|
|
$questionData = [
|
2024-07-19 10:46:18 +00:00
|
|
|
'form_id' => $formId,
|
|
|
|
'text' => $question['text'],
|
|
|
|
'type' => $question['type'],
|
|
|
|
'required' => ($question['required'] == 'true') ? 1 : 0
|
2024-07-15 12:45:25 +00:00
|
|
|
];
|
2024-07-19 10:46:18 +00:00
|
|
|
|
2024-07-15 12:45:25 +00:00
|
|
|
$this->db->insert('questions', $questionData);
|
|
|
|
$questionId = $this->db->insert_id(); // Get the inserted question_id
|
2024-07-19 10:46:18 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2024-07-15 12:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-19 10:46:18 +00:00
|
|
|
|
2024-07-15 12:45:25 +00:00
|
|
|
return true; // Return true indicating success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|