2024-07-15 12:45:25 +00:00
|
|
|
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class New_form_controller extends CI_Controller {
|
|
|
|
|
|
|
|
public function submit_form() {
|
2024-07-19 10:46:18 +00:00
|
|
|
if (!$this->session->userdata('logged_in')) {
|
|
|
|
// If not logged in, redirect to login page
|
|
|
|
redirect('users/login');
|
|
|
|
}
|
|
|
|
// Decode the formData from the POST request
|
2024-07-15 12:45:25 +00:00
|
|
|
$formData = $this->input->post('formData');
|
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
// Check if form_id is set in session
|
|
|
|
$formId = $this->session->userdata('form_id');
|
2024-07-15 12:45:25 +00:00
|
|
|
if ($formId) {
|
2024-07-19 10:46:18 +00:00
|
|
|
// Load the model and save form data
|
2024-07-15 12:45:25 +00:00
|
|
|
$this->load->model('new_form_model');
|
2024-07-19 10:46:18 +00:00
|
|
|
$saveStatus = $this->new_form_model->save_form_data($formId, $formData);
|
2024-07-15 12:45:25 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
if ($saveStatus) {
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']);
|
|
|
|
} else {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Failed to save form data']);
|
|
|
|
}
|
2024-07-15 12:45:25 +00:00
|
|
|
} else {
|
2024-07-19 10:46:18 +00:00
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Form ID not found in session']);
|
2024-07-15 12:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-19 10:46:18 +00:00
|
|
|
?>
|