CodeIgniter_Gforms/application/controllers/Forms.php

70 lines
2.0 KiB
PHP
Raw Normal View History

2024-07-11 13:04:55 +00:00
<?php
class Forms extends CI_Controller
{
2024-07-14 21:04:04 +00:00
public function __construct() {
parent::__construct();
$this->load->model('Form_model');
}
2024-07-11 13:04:55 +00:00
public function create(){
//check login
if(!$this->session->userdata('logged_in')){
redirect('users/login');
}
2024-07-12 09:55:29 +00:00
$data['title'] = 'Create Form';
2024-07-12 06:21:27 +00:00
$this->load->view('templates/header');
2024-07-11 13:04:55 +00:00
$this->load->view('forms/create', $data);
$this->load->view('templates/footer');
}
2024-07-12 06:21:27 +00:00
2024-07-14 21:04:04 +00:00
2024-07-12 06:21:27 +00:00
public function submit_form() {
$formData = $this->input->post('formData');
$decodedData = json_decode($formData, true);
// Process the form data here
// Example: Save the form data to the database
$this->load->model('Form_model');
2024-07-12 09:55:29 +00:00
2024-07-12 06:21:27 +00:00
$this->Form_model->save_form_data($decodedData);
echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']);
}
2024-07-14 21:04:04 +00:00
public function my_forms() {
$this->load->model('Form_model');
$data['forms'] = $this->Form_model->get_all_forms();
$this->load->view('templates/header');
$this->load->view('forms/myforms', $data);
$this->load->view('templates/footer');
}
public function my_drafts() {
$this->load->model('Form_model');
$data['forms'] = $this->Form_model->get_all_forms();
$this->load->view('templates/header');
$this->load->view('forms/mydrafts', $data);
$this->load->view('templates/footer');
}
public function view_form($form_id) {
$data['form'] = $this->Form_model->get_form_by_id($form_id);
$data['questions'] = $this->Form_model->get_questions_by_form_id($form_id);
foreach ($data['questions'] as &$question) {
$question->options = $this->Form_model->get_options_by_question_id($question->question_id);
}
$this->load->view('templates/header', $data);
$this->load->view('forms/view_form', $data);
$this->load->view('templates/footer', $data);
}
2024-07-11 13:04:55 +00:00
}