43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace application\controllers\Testing;
|
||
|
|
||
|
// defined('BASEPATH') or exit('No direct script access allowed')
|
||
|
|
||
|
final class Form extends CI_Controller
|
||
|
{
|
||
|
public function __construct()
|
||
|
{
|
||
|
parent::__construct();
|
||
|
|
||
|
$this->load->model('Form_model');
|
||
|
}
|
||
|
|
||
|
public function submit(): void
|
||
|
{
|
||
|
if (!$this->session->userdata('logged_in')) {
|
||
|
// If not logged in, redirect to login page
|
||
|
redirect('users/login');
|
||
|
}
|
||
|
|
||
|
$response = $this->Form_model->save_form($form_data) ? array('status' => 'success', 'message' => 'Form submitted successfully.')
|
||
|
: array('status' => 'error', 'message' => 'Error submitting form.');
|
||
|
|
||
|
echo json_encode($response);
|
||
|
}
|
||
|
|
||
|
public function view($form_id): void
|
||
|
{
|
||
|
$data['title'] = $this->Form_model->get_form_title($form_id);
|
||
|
|
||
|
if ($data['title'] === null) {
|
||
|
// Show 404 if form_id is invalid
|
||
|
show_404();
|
||
|
}
|
||
|
|
||
|
$this->load->view('templates/forms_ui', $data);
|
||
|
}
|
||
|
}
|