CodeIgniter_Gforms/application/models/Form_model.php

36 lines
974 B
PHP
Raw Normal View History

2024-07-12 09:55:29 +00:00
<?php
2024-07-12 09:53:54 +00:00
class Form_model extends CI_Model {
public function save_form_data($formData) {
2024-07-12 09:55:29 +00:00
$user_id = $this->session->userdata('user_id');
2024-07-12 09:53:54 +00:00
// Save the form data to the database
$this->db->insert('forms', [
'title' => $formData['title'],
2024-07-12 09:55:29 +00:00
'description' => $formData['description'],
'user_id' => $user_id
2024-07-12 09:53:54 +00:00
]);
$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
]);
}
}
}
}
}