2024-07-12 11:50:41 +00:00
|
|
|
<?php
|
|
|
|
|
2024-08-07 06:54:13 +00:00
|
|
|
namespace application\controllers;
|
2024-07-12 11:50:41 +00:00
|
|
|
|
2024-08-05 04:41:20 +00:00
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
2024-08-07 09:28:43 +00:00
|
|
|
|
2024-08-08 11:48:50 +00:00
|
|
|
use application\models\Form_model;
|
2024-08-05 04:41:20 +00:00
|
|
|
|
|
|
|
class Form extends CI_Controller
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
2024-08-05 05:58:57 +00:00
|
|
|
parent::__construct();
|
2024-08-05 07:23:53 +00:00
|
|
|
$this->load->model('Form_model');
|
2024-08-05 05:58:57 +00:00
|
|
|
}
|
|
|
|
public function submit()
|
2024-08-05 04:41:20 +00:00
|
|
|
{
|
2024-08-08 11:48:50 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
if (!$this->session->userdata('logged_in')) {
|
2024-08-05 10:19:43 +00:00
|
|
|
// If not logged in, redirect to login page
|
2024-07-19 10:46:18 +00:00
|
|
|
redirect('users/login');
|
2024-08-07 06:18:44 +00:00
|
|
|
}$form_data = json_decode($this->input->raw_input_stream, true);
|
2024-08-05 04:41:20 +00:00
|
|
|
$this->load->model('Form_model');
|
2024-07-12 11:50:41 +00:00
|
|
|
if ($this->Form_model->save_form($form_data)) {
|
|
|
|
$response = array('status' => 'success', 'message' => 'Form submitted successfully.');
|
|
|
|
} else {
|
|
|
|
$response = array('status' => 'error', 'message' => 'Error submitting form.');
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($response);
|
|
|
|
}
|
2024-08-05 04:41:20 +00:00
|
|
|
public function view($form_id)
|
|
|
|
{
|
2024-07-23 12:54:27 +00:00
|
|
|
$data['title'] = $this->Form_model->get_form_title($form_id);
|
|
|
|
if ($data['title'] === null) {
|
|
|
|
show_404(); // Show 404 if form_id is invalid
|
2024-08-06 09:17:03 +00:00
|
|
|
}$this->load->view('templates/forms_ui', $data);
|
2024-07-23 12:54:27 +00:00
|
|
|
}
|
2024-08-05 04:41:20 +00:00
|
|
|
}
|