google_forms/application/controllers/New_form_controller.php

29 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2024-07-15 12:45:25 +00:00
<?php
2024-08-09 12:04:48 +00:00
defined('BASEPATH') or exit('No direct script access allowed');
2024-07-15 12:45:25 +00:00
2024-08-09 12:04:48 +00:00
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
2024-07-22 09:49:37 +00:00
echo json_encode(['status' => 'error', 'message' => 'User not logged in']);
return;
2024-08-09 12:04:48 +00:00
}// Decode the formData from the POST request$formData = $this->input->post('formData');
// 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-08-09 12:04:48 +00:00
// Load the model and save form data$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
}
}
}