diff --git a/application/config/routes.php b/application/config/routes.php
index 3b91ad3..1e47882 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -7,5 +7,7 @@ $route['default_controller'] = 'home/index2';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['start'] = 'home/index';
+$route['new_form'] = 'home/create_form';
+$route['title_desc'] = 'home/title';
diff --git a/application/controllers/Form.php b/application/controllers/Form.php
new file mode 100644
index 0000000..1b70743
--- /dev/null
+++ b/application/controllers/Form.php
@@ -0,0 +1,22 @@
+load->model('Form_model');
+ }
+
+ public function submit() {
+ $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);
+ }
+}
\ No newline at end of file
diff --git a/application/controllers/Home.php b/application/controllers/Home.php
index bc84a1f..d2d129a 100644
--- a/application/controllers/Home.php
+++ b/application/controllers/Home.php
@@ -34,7 +34,13 @@ class Home extends CI_Controller
$this->load->view('templates/footer');
}
-public function create_form(){
+public function design_form(){
$this->load->view('templates/forms_ui');
}
+public function title(){
+ $this->load->view('templates/header');
+ $this->load->view('templates/form_title');
+ $this->load->view('templates/footer');
+
+}
}
\ No newline at end of file
diff --git a/application/controllers/New_form.php b/application/controllers/New_form.php
new file mode 100644
index 0000000..c4e0cb3
--- /dev/null
+++ b/application/controllers/New_form.php
@@ -0,0 +1,32 @@
+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/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('home/design_form');
+ }
+
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/application/controllers/Users.php b/application/controllers/Users.php
index 8571e81..fbb0e0d 100644
--- a/application/controllers/Users.php
+++ b/application/controllers/Users.php
@@ -27,8 +27,14 @@ class Users extends CI_Controller
}
}
- //login user
+
+/**
+ * function to login into google forms
+ * @param null
+ * @return mixed(data return type)
+ * @author torun
+ */
public function login()
{
$data['title'] = 'Sign In';
@@ -48,22 +54,24 @@ class Users extends CI_Controller
$password = md5($this->input->post('password'));
$this->load->model('user_model');
// Login user
- $user_id = $this->user_model->login($username, $password);
+ $person_id = $this->user_model->login($username, $password);
- if ($user_id) {
+ if ($person_id) {
// Create session
$user_data = array(
- 'user_id' => $user_id,
+ 'user_id' => $person_id,
'username' => $username,
'logged_in' => true
);
$this->session->set_userdata($user_data);
+ $person_id = $this->session->userdata('user_id');
+
// Set message
$this->session->set_flashdata('user_loggedin', 'You are now logged in');
- redirect('start');
+ redirect('title_desc');
} else {
// Set message
$this->session->set_flashdata('login_failed', 'Login is invalid');
diff --git a/application/controllers/Your_controller.php b/application/controllers/Your_controller.php
new file mode 100644
index 0000000..4700dd6
--- /dev/null
+++ b/application/controllers/Your_controller.php
@@ -0,0 +1,20 @@
+session->userdata('user_id');
+
+ // Query to fetch form_id from database based on user_id
+ $form_id = $this->your_model->getFormIdByUserId($user_id); // Replace with your actual model method
+
+ // Return form_id as JSON response
+ $this->output
+ ->set_content_type('application/json')
+ ->set_output(json_encode(array('form_id' => $form_id)));
+}
+}
diff --git a/application/models/Create_model.php b/application/models/Create_model.php
new file mode 100644
index 0000000..9b8723f
--- /dev/null
+++ b/application/models/Create_model.php
@@ -0,0 +1,24 @@
+
+session->userdata('user_id');
+
+ // Prepare data to insert into forms table
+ $data = array(
+ 'user_id' => $user_id,
+ 'title' => $this->input->post('title'),
+ 'description' => $this->input->post('description')
+ );
+
+ // Insert data into forms table
+ $this->db->insert('forms', $data);
+ }
+}
+
+?>
diff --git a/application/models/Form_model.php b/application/models/Form_model.php
new file mode 100644
index 0000000..c3c4e5a
--- /dev/null
+++ b/application/models/Form_model.php
@@ -0,0 +1,40 @@
+db->trans_start();
+
+ foreach ($form_data as $section) {
+ $question_data = array(
+ 'form_id' => $section['form_id'],
+ 'text' => $section['text'],
+ 'type' => $section['type'],
+ 'required' => $section['required'],
+ 'created_at' => date('Y-m-d H:i:s')
+ );
+
+ $this->db->insert('questions', $question_data);
+ $question_id = $this->db->insert_id();
+
+ foreach ($section['options'] as $option_text) {
+ $option_data = array(
+ 'question_id' => $question_id,
+ 'text' => $option_text,
+ 'created_at' => date('Y-m-d H:i:s')
+ );
+
+ $this->db->insert('options', $option_data);
+ }
+ }
+
+ $this->db->trans_complete();
+
+ if ($this->db->trans_status() === FALSE) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/models/Your_model.php b/application/models/Your_model.php
new file mode 100644
index 0000000..39bf107
--- /dev/null
+++ b/application/models/Your_model.php
@@ -0,0 +1,19 @@
+
+db->select('form_id');
+ $this->db->where('user_id', $user_id);
+ $query = $this->db->get('forms'); // Replace 'your_forms_table' with your actual table name
+
+ if ($query->num_rows() > 0) {
+ $row = $query->row();
+ return $row->form_id;
+ } else {
+ return null; // Handle case when form_id is not found
+ }
+}
+}
\ No newline at end of file
diff --git a/application/views/templates/form_title.php b/application/views/templates/form_title.php
new file mode 100644
index 0000000..af75e00
--- /dev/null
+++ b/application/views/templates/form_title.php
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/application/views/templates/forms2.txt b/application/views/templates/forms2.txt
index badaaed..f6c5c0c 100644
--- a/application/views/templates/forms2.txt
+++ b/application/views/templates/forms2.txt
@@ -1,280 +1,46 @@
-To achieve the functionality where the form data is submitted and stored in the database using CodeIgniter, we need to set up the necessary controllers, models, and views. Below is a detailed guide on how to implement this.
+**********MODEL****************
-### Step 1: Update JavaScript (scripts.js)
+db->trans_start();
- // Function to add an option based on type
- function addOption(type, container) {
- let optionIndex = container.children().length + 1;
- let optionHtml;
- if (type === 'multiple-choice' || type === 'checkboxes') {
- optionHtml = `
-