diff --git a/application/config/routes.php b/application/config/routes.php
index 92e526a..fc85526 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -21,4 +21,9 @@ $route['edit/(:num)'] = 'Form_controller/edit_form/$1';
$route['form_preview/(:num)'] = 'forms/preview_back/$1';
$route['responses/(:num)'] = 'Response_submit/view_responses/$1';
-$route['designform'] = 'homepage/design_form';
+$route['designform/(:num)'] = 'homepage/design_form/$1';
+$route['response_preview/(:num)'] = 'forms/response_preview/$1';
+
+$route['title'] = 'homepage/title';
+
+// $route['designform'] = 'homepage/design_form';
diff --git a/application/controllers/Form.php b/application/controllers/Form.php
index 5077544..67d5edd 100644
--- a/application/controllers/Form.php
+++ b/application/controllers/Form.php
@@ -23,4 +23,14 @@ class Form extends CI_Controller {
echo json_encode($response);
}
+
+ 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);
+ }
}
\ No newline at end of file
diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php
index d916740..4624c24 100644
--- a/application/controllers/Forms.php
+++ b/application/controllers/Forms.php
@@ -38,7 +38,7 @@ class Forms extends CI_Controller
{
if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page
- redirect('users/login');
+ redirect('users/login/'.$form_id);
}
// Load the model that handles the form data
diff --git a/application/controllers/Home.php b/application/controllers/Homepage.php
similarity index 100%
rename from application/controllers/Home.php
rename to application/controllers/Homepage.php
diff --git a/application/controllers/New_form.php b/application/controllers/New_form.php
index 0d12807..4099bcc 100644
--- a/application/controllers/New_form.php
+++ b/application/controllers/New_form.php
@@ -1,36 +1,29 @@
session->userdata('logged_in')) {
// If not logged in, redirect to login page
redirect('users/login');
}
+
$data['title'] = 'Form Details';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('description', 'Description', 'required');
-
-
+
if ($this->form_validation->run() === FALSE) {
$this->load->view('templates/header');
- $this->load->view('templates/form_title',$data);
+ $this->load->view('templates/form_title', $data);
$this->load->view('templates/footer');
} else {
- // $enc_password = md5($this->input->post('password'));
$this->load->model('create_model');
- // $user_id = $this->session->userdata('user_id');
-
-
- $this->create_model->details();
- // $this->user_model->register();
-
-
- // $this->session->set_flashdata('user_registered', 'You are now registered and can log in');
- redirect('designform');
+ $form_id = $this->create_model->details(); // Get the new form_id
+
+ // Redirect to the form view with the form_id
+ redirect('form/view/' . $form_id);
}
-
}
+
}
?>
\ No newline at end of file
diff --git a/application/controllers/New_form_controller.php b/application/controllers/New_form_controller.php
index e42fea1..c49e72c 100644
--- a/application/controllers/New_form_controller.php
+++ b/application/controllers/New_form_controller.php
@@ -12,7 +12,6 @@ class New_form_controller extends CI_Controller {
// 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');
if ($formId) {
diff --git a/application/controllers/Publish_controller.php b/application/controllers/Publish_controller.php
index c159a7c..43ab23d 100644
--- a/application/controllers/Publish_controller.php
+++ b/application/controllers/Publish_controller.php
@@ -10,7 +10,7 @@ class Publish_controller extends CI_Controller {
// If not logged in, redirect to login page
redirect('users/login');
}
- $response_link = base_url("forms/response_preview/" . $form_id);
+ $response_link = base_url("response_preview/" . $form_id);
$this->load->model('Publish_model');
// Update is_published to 1 and set the response link
$this->Publish_model->update_form($form_id, [
diff --git a/application/controllers/Users.php b/application/controllers/Users.php
index 9d42e47..f1f0e51 100644
--- a/application/controllers/Users.php
+++ b/application/controllers/Users.php
@@ -35,9 +35,10 @@ class Users extends CI_Controller
* @return mixed(data return type)
* @author torun
*/
- public function login()
+ public function login($form_id = null)
{
$data['title'] = 'Sign In';
+ $data['form_id'] = $form_id;
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
@@ -71,7 +72,11 @@ class Users extends CI_Controller
// Set message
$this->session->set_flashdata('user_loggedin', 'You are now logged in');
- redirect('home');
+ if ($form_id) {
+ redirect('forms/response_preview/'.$form_id);
+ } else {
+ redirect('home'); }
+
} else {
// Set message
$this->session->set_flashdata('login_failed', 'Login is invalid');
diff --git a/application/models/Create_model.php b/application/models/Create_model.php
index 1d4fd94..69b8bab 100644
--- a/application/models/Create_model.php
+++ b/application/models/Create_model.php
@@ -20,7 +20,7 @@ class Create_model extends CI_Model {
$formId = $this->db->insert_id();
$this->session->set_userdata('form_id', $formId);
-
+return $formId;
}
}
diff --git a/application/models/Form_model.php b/application/models/Form_model.php
index aad772a..b3969ac 100644
--- a/application/models/Form_model.php
+++ b/application/models/Form_model.php
@@ -37,4 +37,20 @@ class Form_model extends CI_Model {
return true;
}
}
+ public function __construct() {
+ $this->load->database();
+ }
+
+ public function get_form_title($form_id) {
+ $this->db->select('title'); // Assuming the title column in the forms table is called 'title'
+ $this->db->from('forms');
+ $this->db->where('id', $form_id);
+ $query = $this->db->get();
+
+ if ($query->num_rows() > 0) {
+ return $query->row()->title;
+ } else {
+ return null;
+ }
+ }
}
\ No newline at end of file
diff --git a/application/views/Tables/draft.php b/application/views/Tables/draft.php
index f6f9d1c..19daee0 100644
--- a/application/views/Tables/draft.php
+++ b/application/views/Tables/draft.php
@@ -1,3 +1,8 @@
+
@@ -17,22 +22,24 @@ Drafts
- Form_Id |
+ Drafts |
Title |
- Description |
Created On |
Edit |
Delete |
+ Preview |
-
-
- id; ?> |
- title; ?>
+
+ |
+ |
+
+ title; ?>
|
- description; ?> |
+
created_at; ?> |
Delete
|
+
+
+
+
+ |
diff --git a/application/views/Tables/list_forms.php b/application/views/Tables/list_forms.php
index d7e00e9..ee98e4b 100644
--- a/application/views/Tables/list_forms.php
+++ b/application/views/Tables/list_forms.php
@@ -1,3 +1,23 @@
+
+
+
+
+
+
+ Form List
+
+
+
+
+
@@ -14,27 +34,33 @@
-
+
- Form_Id |
+ Forms |
Title |
Description |
Created On |
Status |
+ Preview |
-
-
- id; ?> |
- title; ?>
+
+ |
+ |
+
+ title; ?>
|
description; ?> |
created_at; ?> |
+ is_published ? 'Published' : 'Draft'); ?> |
- is_published ? 'Published' : 'Draft'); ?>
+
+
+
|
@@ -45,3 +71,18 @@
+
+
+
+
diff --git a/application/views/edit_form_view.php b/application/views/edit_form_view.php
index fd53d9f..9407a22 100644
--- a/application/views/edit_form_view.php
+++ b/application/views/edit_form_view.php
@@ -4,12 +4,65 @@
Edit Form
-
+
-
+
+
+
+
+
+
+
+
+
+ session->flashdata('user_registered')): ?>
+
session->flashdata('user_registered'); ?>
+
+
+ session->flashdata('login_failed')): ?>
+
session->flashdata('login_failed'); ?>
+
+
+ session->flashdata('user_loggedin')): ?>
+
session->flashdata('user_loggedin'); ?>
+
+
+ session->flashdata('user_loggedout')): ?>
+
session->flashdata('user_loggedout'); ?>
+
+
+
+
-
+
+
@@ -65,9 +119,33 @@