google_forms/application/controllers/Form.php

36 lines
1.0 KiB
PHP
Raw Normal View History

2024-07-12 11:50:41 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Form extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('Form_model');
}
public function submit() {
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');
}
2024-07-12 11:50:41 +00:00
$form_data = json_decode($this->input->raw_input_stream, true);
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-07-23 12:54:27 +00:00
public function view($form_id) {
$data['title'] = $this->Form_model->get_form_title($form_id);
if ($data['title'] === null) {
show_404(); // Show 404 if form_id is invalid
}
$this->load->view('templates/forms_ui',$data);
}
2024-07-12 11:50:41 +00:00
}